Conquest

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

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.

Problem information

Author: Félix Miravé

Generation: 2026-01-25T11:24:42.996Z

© Jutge.org, 2006–2026.
https://jutge.org