Problem description said last talk about the sea East group face strife, the company's elder also only left XHD couple two people. Obviously, as a businessman who has worked hard for years, XHD will not sit idly by.
One day, when he was thinking about the remedy, suddenly thought of his family heirloom, that is the company set up, the father as a gift to send a brocade bag, Xu father at that time, not to the last resort, do not open it. "Now is not the time to do it most?" , while thinking, XHD side found this careful custody of the brocade bag, open a look, inside only a word "Hangzhou North foot thousand people hole has treasure".
Apart, Xhd pick up a big pocket on the start, this thousand man hole he is know, small time, dad once brought him to this secluded intersection, and told him, this is thousand man hole. He now understood the meaning of his father's words.
Despite a little impression, Xhd still spent a lot of energy to find this unusual hidden hole, into a look, almost stunned, really is dazzling! But despite the variety of baby, but the amount of each treasure is not much, of course, each of the baby unit volume of the price is not the same, in order to save HDU, now please help to calculate as soon as possible XHD can bring back how much value of the baby? (assuming that the baby can be split, the value of the split is proportional to the corresponding volume)
Input inputs contain multiple test instances, the first line of each instance being two integers V and n (v,n<100), each representing the capacity of the pocket and the kind of baby, followed by n rows each containing 2 integer pi and mi (0<pi,mi<10), Indicates the unit price and the corresponding volume of a baby, and V is 0 to end the input.
Output for each test instance, print out how much value XHD can fetch, with the output of each instance on one line.
Sample Input
2 23 12 30
Sample Output
5
Idea: Greedy algorithm, the value of each treasure to sort, from the beginning of value, pocket capacity reduction, when the volume of a treasure is larger than the remaining pocket capacity, take the last
Some items--saving HDU