Conquest P57013


Statement
 

pdf   zip

0.52

It is summer in the land of Max-Flow and Lord Push-Relabel wants to build a swimming pool in the yard next to his castle, which will cost gg gold coins. So he is sending his invincible army to conquer some of the nn nearby towns. His soldiers can conquer one town per day, and afterwards they will use one of the following methods to acquire gold from it:

0.48

  • Taxes: the town will pay tit_i gold coins every day, starting the same day it is conquered.

  • Sacking: the army will get sis_i gold coins by looting the town the very same day it is conquered, but this will leave the town unable to pay taxes in the future.

Lord Push-Relabel wants to minimize the number of days to acquire the desired amount of gold gg. Please plan which towns to conquer, in what order, and for each conquered town whether it should be taxed or sacked.

Input

Input consists of several cases. Every case begins with gg and nn, followed nn pairs tit_i sis_i. Assume 1g10171 \le g \le 10^{17}, 1n10001 \le n \le 1000, 1ti1071 \le t_i \le 10^7, and ti<si1014t_i < s_i \le 10^{14}.

Output

For every case, print the minimum number of days needed to collect at least gg gold coins.

Public test cases
  • Input

    100 1
    99 100
    100 1
    3 99
    32 2
    8 17  7 14
    32 2
    7 14  9 17
    15 3
    4 6  2 7  1 2
    76543210987654321 1
    7654321 43210987654321
    

    Output

    1
    34
    3
    2
    2
    10000000130
    
  • Information
    Author
    Félix Miravé
    Language
    English
    Official solutions
    C++
    User solutions
    C++