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




贪心,每段尽量向上爬。



#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000000)
#define MAXM (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,m;
int main()
{
// freopen("c.in","r",stdin);
// freopen(".out","w",stdout);

cin>>n>>m;
int d1,h1,ans;
For(i,m)
{
int d,h;
scanf("%d%d",&d,&h);
if (i!=1)
{
if (d-d1<abs(h-h1))
{
cout<<"IMPOSSIBLE"<<endl;
return 0;
}

int dd=d-d1,dh=abs(h-h1);
ans=max(ans,max(h1,h)+(dd-dh)/2);


}
d1=d,h1=h;
if (i==1) ans=h+d-1;
}
ans=max(ans,h1+n-d1);
cout<<ans<<endl;

return 0;
}