PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000181. Rồng nhiều đầu (Zmei Gorynich)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Rồng nhiều đầu (Zmei Gorynich)

Zmei Gorynich

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You fight Zmei Gorynich, a dragon initially having xx heads. There are nn attack types. Attack ii cuts off min⁡(di,h)\min(d_i,h) heads when hh heads currently remain. If at least one head remains after the cut, the dragon immediately regenerates hih_i heads. If no heads remain, the dragon is defeated and does not regenerate. You may use any attack type any number of times in any order. Find the minimum number of attacks required, or print -1 if the dragon cannot be defeated.

Input

Line 1 contains two integers nn and xx: the number of attack types and the initial number of heads.

Each of the next nn lines contains two integers did_i and hih_i: the number of heads type ii can cut off and the number that regenerate if the dragon survives.

Output

Print one integer: the minimum number of attacks, or -1 if defeating the dragon is impossible.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 1≤x≤1001\le x\le 100; 1≤di,hi≤1001\le d_i,h_i\le 100 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤501\le n\le 50; 1≤x≤1000001\le x\le 100000; 1≤di,hi≤1000001\le d_i,h_i\le 100000 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤1001\le n\le 100; 1≤x≤10000000001\le x\le 1000000000; 1≤di,hi≤10000000001\le d_i,h_i\le 1000000000 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

3 10
6 3
8 2
1 4

Output

2

Explanation

The dragon starts with 1010 heads. Attack (6,3)(6,3) cuts 66, leaving 44, then regenerates 33, giving 77. Attack (8,2)(8,2) cuts all 77 remaining heads and ends the fight. No attack can cut all 1010 initial heads in one blow, so two attacks are optimal.

Example 2

Input

2 15
10 11
14 100

Output

-1

Explanation

Neither attack can kill a dragon with 1515 heads immediately. Attack (10,11)(10,11) increases the count by 11 while it survives, and (14,100)(14,100) increases it even further. The number of heads therefore never decreases enough to permit a finishing attack.