Hide

Problem I
Spilahlustun

Languages en is

Jörmunrekur’s wallet has gotten frightfully light towards the end of his studies, so he is looking for creative ways to fix that problem. After taking a course in probability theory he knows that most betting games played with a deck of cards will not be in his favour unless he has some trick up his sleeve. And that he does, he has gotten himself a small microphone which he will attach to the underside of the table at which he is playing. The cards are shuffled using a small automatic machine to make sure things are fair. The machine is silent enough to not be heard by even the most perceptive of people and does its work outside the view of the players. It shuffles by taking some section of the cards and flipping the section over as a whole before inserting it back into the deck, repeating as often as necessary. After shuffling, when dealing the cards, it simply turns the card over as it deals, if the card is upside down. Through the microphone Jörmunrekur can pick up the imperceptibly silent sounds of the shuffler, giving away how far it moves before picking up a section to flip, and how much the grabber has to widen to get a hold of that section. Thus he can know what section is flipped each time. But he has to focus on the game, he does not need to know what sections get flipped, he needs to know in what order the cards will be dealt. He needs a program to take care of this for him, are you up to the task? We number the cards from $1$ to $n$. Initially, the top card is $1$, the next is $2$, and so on, and finally, the bottom card is $n$. All cards face down initially.

Input

The first line of input contains two integers $n$, the number of cards, where $1 \leq n \leq 5 \cdot 10^5$, and $q$, the number of flips, where $1 \leq q \leq 5 \cdot 10^5$. Then $q$ lines follow, each describing one flip in the form of two numbers $i$ and $j$, such that $1 \leq i \leq j \leq n$. This means that the $i$-th through $j$-th cards from the top, including both endpoints, are picked up together by the grabber and flipped, before being inserted back into the deck. The flips are given in the same order as they are performed.

Output

Print the numbers of the cards from top to bottom, as they are ordered at the end of the shuffle. If card $k$ faces up at the end, print $-k$ instead of $k$.

Sample Input 1 Sample Output 1
5 1
2 4
1 -4 -3 -2 5 
Sample Input 2 Sample Output 2
7 6
1 3
3 7
2 3
4 7
1 1
4 4
3 7 2 1 4 5 6 

Please log in to submit a solution to this problem

Log in