eolymp
bolt
Try our new interface for solving problems
Problems

Old Wine Into New Bottles

Old Wine Into New Bottles

\includegraphics{https://static.e-olymp.com/content/99/99638061bc05405c8f28d0412b2b1ca8180b55ed.jpg} 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. \InputFile The first line of input contains two integers: the amount of wine to be bottled (in litres, between \textbf{0} and \textbf{1000000}) and the number of sizes of bottles (between \textbf{1} and \textbf{100}). For each size of bottle, one line of input follows giving the minimum and maximum capacity of each bottle in millilitres. The maximum capacity is not less than \textbf{325} ml and does not exceed \textbf{4500} ml. The minimum capacity is not less than \textbf{95}\% and not greater than \textbf{99}\% of the maximum capacity. You may assume that an unlimited number of each bottle is available. \OutputFile Your output should consist of a single integer: the amount of wine, in ml, that cannot be bottled.
Time limit 1 second
Memory limit 64 MiB
Input example #1
10 2
4450 4500
725 750
Output example #1
250