C. Tourist's Notes
time limit per test
memory limit per test
input
output
n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all i's from 1 to n - 1 the inequality |hi - hi + 1| ≤ 1
|hi - hi + 1| ≤ 1.
Input
n and m (1 ≤ n ≤ 108, 1 ≤ m ≤ 105) — the number of days of the hike and the number of notes left in the journal.
m lines contain two space-separated integers di and hdi (1 ≤ di ≤ n, 0 ≤ hdi ≤ 108) — the number of the day when the i-th note was made and height on the di-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all i from 1 to m - 1the following condition holds: di < di + 1.
Output
If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.
IMPOSSIBLE' (without the quotes).
Sample test(s)
input
8 2 2 0 7 0
output
2
input
8 3 2 0 7 0 8 3
output
IMPOSSIBLE
Note
(0, 0, 1, 2, 1, 1, 0, 1).
h7 and h8
贪心,每段尽量向上爬。