Gimli's Gullet

No attempts yetTime limit1sMemory limit256 MB

Problem

Legolas and Gimli are packing rations before they leave the Woodland Realm, and the kitchen has badly underestimated the belly of a dwarf. Gimli refuses to take a step until his pack holds as many calories as it can.

The kitchen has MM kinds of food. Each kind has a volume per serving and a calorie count per serving. Gimli can order any number of servings of a kind, including none. Choose how many servings of each food to order so that the total volume fits in the space left in the pack and the total calorie count is as large as possible.

Several orders can reach the same largest calorie count. In that case the answer is the one whose sequence of quantities comes first in lexicographic order: order as few servings as possible of the first food, then, under that condition, as few servings as possible of the second food, and so on.

Input

The input holds several test cases. The first line of a test case has one integer CC, the space left in Gimli's pack in cubic centimeters. The second line has one integer MM, the number of foods on offer. Each of the next MM lines has two integers, the volume viv_i of one serving in cubic centimeters and its calorie count cic_i. These lines are given in non-decreasing order of volume.

A test case whose first line is 0 marks the end of the input, and it produces no output.

1C100001 \le C \le 10000, 1M201 \le M \le 20, 1vi100001 \le v_i \le 10000, 0ci1000000 \le c_i \le 100000, and v1v2vMv_1 \le v_2 \le \dots \le v_M. At most 10 test cases come before the terminating 0.

Output

For each test case, print one line with MM integers separated by single spaces. The ii-th integer is the number of servings of the ii-th food that Gimli should order.

When several orders reach the largest calorie count, print the sequence of quantities that comes first in lexicographic order.