The UNICAMP team won 1st place in the marathon in Chapecó, a feat achieved only $$$3$$$ other times so far. Indeed, it was a very happy moment for everyone at UNICAMP. The Brazilian final of 2023 took place in Chapecó, being the first edition to qualify teams for the Latin American final.
During the competition, something tragic happened to the team "We Are Living a Dream": they finished in 16th place, but only the top $$$15$$$ qualified for Latam.
Moved by the situation, the SBC decided to conduct a survey to measure the happiness of each team after the competition, assigning each a happiness score between $$$0$$$ and $$$10^9$$$. After analyzing the data, a curious conclusion emerged: the happiness of the teams, as a function of the final placement, behaves like a non-increasing function from position 1 to the first position that does not qualify for Latam, and like a non-decreasing function from the first position that does not qualify to the last place.
To avoid further frustrations, the teams from Unicamp asked Carlinhos to reveal the number of spots available for Latam. However, Carlinhos explained that this information is confidential. Still, using his mysterious statistical methods, he agreed to answer questions by providing the happiness level of a team at a certain placement.
With these answers, the teams realized that it is possible to determine an interval containing all possible values for the number of spots — but they need your help to calculate this interval.
Example of happiness as a function of position. In the test cases, the coordinates are integers. Note that the shape of the curve can vary greatly, but it is guaranteed that it goes down and then up, possibly maintaining the same value at times. The first line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N \leq 10^9$$$, $$$1 \leq M \leq 10^5$$$) — the total number of teams competing and the number of questions asked to Carlinhos. The next $$$M$$$ lines contain two integers $$$P$$$ and $$$V$$$ ($$$1 \leq P \leq N$$$, $$$1 \leq V \leq 10^9$$$) — indicating that the happiness at position $$$P$$$ is $$$V$$$.
It is guaranteed that the values of $$$P$$$ are different.
After each of the $$$M$$$ questions, print two values $$$L$$$ and $$$R$$$, representing the smallest possible interval [L, R] that contains all the still possible values for the number of spots for Latam, based on the questions asked up to that moment.
Note that it is possible for the number of spots to be $$$0$$$.
20 516 414 1018 1519 1620 18
0 20 14 20 14 16 14 16 14 16
10 42 54 56 58 5
0 10 0 10 0 10 0 10
10 58 45 26 17 39 5
0 10 0 6 5 6 5 5 5 5
It is possible for many positions to have the same happiness value, including the minimum happiness value.