Old Wine Into New Bottles#3497

Old Wine Into New Bottles

1 second
64 megabytes
Very easy

Wine bottles are never completely filled: a small amount of air must be left in the neck to allow for thermal expansion and contraction. If too little air is left in the bottle, the wine may expand and expel the cork; if too much air is left in the bottle, the wine may spoil. Thus each bottle has a minimum and maximum capacity.

Given a certain amount of wine and a selection of bottles of various sizes, determine which bottles to use so that each is filled to between its minimum and maximum capacity and so that as much wine as possible is bottled.

Input

The first line contains two integers: the amount of wine to be bottled (in litres, between and ) and the number of bottle sizes (between and ). For each size, one line follows with the minimum and maximum capacity of that bottle type in millilitres. The maximum capacity is not less than ml and does not exceed ml. The minimum capacity is not less than and not greater than of the maximum capacity. You may assume that an unlimited number of each bottle is available.

Output

Output a single integer: the amount of wine, in millilitres, that cannot be bottled.

Examples

Example 1

Loading
Loading