Intergalactic Chords

Maintain an array of N notes (0 to 8); for each chord [a,b] find the most frequent note in the range, break ties by largest, then add it modulo 9 to every note in the range.

Hard8Segment treeImplementationMathBrute forceNo attempts yetTime limit1sMemory limit1024 MB

Problem

The intergalactic piano sonata composition marathon keeps raising the difficulty for its competitors, because more and more beings of superior intelligence enter it.

The piano has NN keys, numbered 00 to N1N-1. The intergalactic tonal system has nine notes, valued 00 to 88. At the start every key is assigned the same note, 11.

A competitor plays a sequence of chords. Each intergalactic chord is made of two distinct keys aa and bb with 0a<b<N0 \le a < b < N. When the chord is played, the piano sounds ff, the most frequent note among the keys in the interval [a,b][a, b]. If several notes tie for most frequent, the piano sounds the largest of them. Right after sounding the note, the piano changes the note assigned to every key in the interval [a,b][a, b]. The new note of key kk, for akba \le k \le b, is its previous note plus ff, modulo 99.

For example, suppose the notes of a piano with N=15N = 15 keys are the following at some moment.

key01234567891011121314
note221454348016201

If the chord [3,9][3, 9] is played, the most frequent note is 44, and the notes after the chord are the following.

key01234567891011121314
note221808783416201

Given the sequence of QQ chords, print the note assigned to each key of the piano after every chord in the sequence has been played.

Input

The first line contains two integers NN and QQ separated by a space, the number of keys of the intergalactic piano and the number of chords. (2N1000002 \le N \le 100000, 1Q1000001 \le Q \le 100000)

Each of the next QQ lines contains two integers AA and BB, one chord. (0A<B<N0 \le A < B < N) The chords are played in the given order.

Output

Print NN integers, one per line, the notes assigned to keys 00 through N1N-1 after all chords have been played.