Hide

Problem G
Shattered Cake

/problems/shatteredcake/file/statement/en/img-0001.png

A rectangular cake is transported via a truck to a restaurant. On the way to the destination, the truck hits a pothole, which shatters the cake into N perfectly rectangular pieces of width wi and length li, for 1iN.

At the destination, the damage is assessed, and the customer decides to order a replacement cake of the same dimensions. Unfortunately, the original order form was incompletely filled and only the width W of the cake is known. The restaurant asks for your help to find out the length L of the cake. Fortunately, all pieces of the shattered cake have been kept.

Input

The input consists of the following integers:

  • on the first line, the width W of the cake;

  • on the second line, the number N of shattered pieces;

  • on each of the next N lines, the width wi and length li of each piece.

Limits

  • 1N5000000;

  • 1W,L10000;

  • for each 1iN, 1wi,li10000.

Output

The output should be the integer L.

Sample Input 1 Sample Output 1
4
7
2 3
1 4
1 2
1 2
2 2
2 2
2 1
6
Hide

Please log in to submit a solution to this problem

Log in