Problem c:old Wine into New bottles
Wine bottles are never completely filled:a small amount to-is left in the must to neck for allow thermal D contraction. If too little the bottle, the wine may expand and expel the cork; If too much of the 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 of bottles of various sizes, determine which bottles to? Filled to between it minimum and maximum capacity and so, as much wine as possible.
Input
The input begins with a single positive integer in a line by itself indicating the number of cases following, each of them as described below. This are followed by a blank line, and there are also a blank line between two consecutive.
The "a" of input contains two integers:the amount of wine to is bottled (in litres, between 0 and 1,000,000) and T He number of sizes of bottles (between 1 and 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 isn't less than 325 ml and does not exceed ML. The minimum capacity is not less than the greater than of the 99% maximum. You may assume this unlimited number of each bottle is available.
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases is separated by a blank line.
Your output should consist of a single integer:the amount of wine, in ML, which cannot be bottled.
Sample Input
2
2
4450 4500
725 750
10000 2
4450 4500
725 750
Sample Output
0