Largest window sum

For every window length K, find the largest possible sum of a length-K window over all non-negative arrays that satisfy each given length bound.

Hard9GreedyPrefix sumMathDynamic programmingNo attempts yetTime limit1sMemory limit512 MB

Problem

Seunghyun plays with an array of NN non-negative integers. The array carries MM special conditions. Condition ii says that every contiguous window of length LiL_i has a sum of at most SiS_i.

Seunghyun wrote down every array that satisfies all of the conditions. For each integer KK between 11 and NN he took every contiguous window of length KK in each of those arrays, computed its sum, and kept the largest value. He is not confident about his arithmetic, so compute the answers for him.

In other words, for each KK report the largest window sum you can reach by choosing an array that satisfies every condition together with a contiguous window of length KK inside it.

Input

The first line contains the number of integers in the array NN (1N2000001 \le N \le 200\,000) and the number of special conditions MM (1M2001 \le M \le 200).

Each of the next MM lines contains two integers LiL_i and SiS_i describing one condition (1iM1 \le i \le M, 1LiN1 \le L_i \le N, 1Si1091 \le S_i \le 10^9).

Several conditions may share the same length.

Output

Print NN lines. Line KK holds the largest sum a contiguous window of length KK can have in an array that satisfies every condition.

Hint

Take N=5N = 5 with two conditions: length 22 with bound 55, and length 33 with bound 77. For the array [1, 4, 1, 0, 5] there is a window of length 1 whose sum is 5, a window of length 2 whose sum is 5, and a window of length 4 whose sum is 10. For the array [3, 2, 2, 1, 4] there is a window of length 3 whose sum is 7, and a window of length 5 whose sum is 12.