You have a backpack that can bear up to w units of weight. Given n objects, each with a weight wi and a value vi, compute the maximum sum of values achievable, in such a way that the sum of weights does not exceed w. Take into account that objects cannot be cut: either you pick them, or you discard them.
Input
Input consists of several cases. Every case begins with w and n, followed by n pairs of integer numbers wi vi. Assume 1 ≤ w ≤ 1000, 1 ≤ n ≤ 1000, 1 ≤ wi ≤ p, and 1 ≤ vi ≤ 106.
Output
For every case, print the maximum value of the objects that can be stored in the backpack.
Input
10 3 7 3000 8 4000 3 2000 10 3 7 3000 8 6000 3 2000 2 4 1 3 1 5 1 7 1 7
Output
5000 6000 14