Under construction

Still being built. Things may change

One Hit

Time limit2sMemory limit1024 MB

Summary
Each skill maps attack x to a*x+b, and the task asks for the fewest skill uses that take starting attack x to at least boss HP y, or -1.
Level

Hard8 of 10

Topics
Greedy, Math, Binary search
Solved
No attempts yet

Problem

MapleStory has buff skills such as Blessing of Maha and Howling that change your attack power. Ims, a veteran player with 20 years of experience, is tired of attack-only builds. He wants to take down bosses in his own way, using buff skills like the ones above.

Ims has NN buff skills. The ii-th skill multiplies attack power by aia_i and then adds bib_i. Here bib_i can be negative. If ai=3a_i = 3 and bi=5b_i = 5, and the current attack power is xx, then after using skill ii the attack power becomes x×3+5x \times 3 + 5. A skill can be used any number of times, and skills are applied in the order they are used.

Ims is clearing QQ dungeons today. Each dungeon has a boss, and each boss has a different HP. The bosses also differ in level, defense rate, and so on, so Ims's starting attack power depends on the boss he faces.

If Ims's attack power is equal to or higher than the boss's HP, he can defeat the boss in one hit. What is the minimum number of skills he must use to defeat the boss in one hit?

Input

The first line contains the number of skills NN and the number of dungeons QQ, separated by a space. (1≤N,Q≤300 0001 \le N, Q \le 300\,000)

From the second line, the next NN lines each contain aia_i and bib_i, the information for skill ii, separated by a space. (1≤ai≤1 000 0001 \le a_i \le 1\,000\,000, −109≤bi≤109-10^9 \le b_i \le 10^9)

The next QQ lines each contain xix_i, the starting attack power in dungeon ii, and yiy_i, the boss HP in that dungeon. (1≤xi,yi≤10121 \le x_i, y_i \le 10^{12})

Output

For each dungeon, print on its own line the minimum number of skills that must be used to defeat the boss in one hit.

If the boss cannot be defeated in one hit with the given skills, print -1.

Examples2

  1. Example 1

    Input
    3 2
    1 8
    2 3
    3 5
    3 14
    1 32
    
    Expected output
    1
    2
    
  2. Example 2

    Input
    2 4
    2 -3
    1 0
    6 8
    5 8
    4 8
    3 8
    
    Expected output
    1
    2
    3
    -1