Shattered Cake

Given the cake's width and the dimensions of all shattered rectangular pieces, sum the piece areas and divide by the width to get the length.

Easy2MathImplementationArrayBrute forceInterviewNo attempts yetTime limit10sMemory limit512 MB

Problem

A shattered cake

A rectangular cake travels to a restaurant on a truck. On the way the truck hits a pothole, and the cake shatters into NN perfectly rectangular pieces. Piece ii has width wiw_i and length lil_i for 1iN1 \le i \le N.

At the restaurant the customer orders a replacement cake of the same size. The original order form was left unfinished, so only the width WW of the cake is known. Every piece of the shattered cake was kept, so the areas of the pieces add up to the area of the original cake. Find the length LL of the cake.

A piece may have turned while the cake broke, so wiw_i can be larger than WW.

Input

The first line contains the width WW of the cake.

The second line contains the number NN of shattered pieces.

Each of the next NN lines contains the width wiw_i and the length lil_i of one piece, separated by a space.

Limits

  • 1N50000001 \le N \le 5\,000\,000
  • 1W,L100001 \le W, L \le 10\,000
  • 1wi,li100001 \le w_i, l_i \le 10\,000 for each 1iN1 \le i \le N

Output

Print the length LL of the cake as an integer on one line.