printРабочее место участника

printЗадачи

2382. Shattered Cake

Ограничения: время – 250ms/500ms, память – 512MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Cinnamon Bun was carrying a rectangular cake to dinning room. On the way to the destination, he stumbled, which shatters the cake in `N` rectangular pieces. Princess Bubblegum decides to order a replacement cake of the same dimensions. Unfortunately, only the width `W` of the cake is known. But all pieces of the shattered cake have been kept and measured.
The Princess asks for your help to find out the length `L` of the cake (`1\ ≤\ L\ ≤\ 10000`).
Input
The input consists of the following integers:
  • on the first line, the width `W` of the cake (`1\ ≤\ W\ ≤\ 10000`);
  • on the second line, the number `N` of shattered pieces (`2\ ≤\ N\ ≤\ 100000`);
  • on each of the next `N` lines, the width `w_i` and length `l_i` of each piece (`1\ ≤\ w_i,\ l_i\ ≤\ max(W,L)`).
Output
The output should be the integer `L`, on a line by itself.

Sample Input

4
7
1 2
2 2
2 3
1 4
1 2
2 2
2 1

Sample Output

6
loading