#include<bits/stdc++.h> usingnamespace std; constint N = 2e6+10; int n,k,st[N][21],ans; set<int> s; structlin{ int l,r; } l[N]; boolcmp(lin x,lin y){ return x.l<y.l; } voidpre(){ for (int i=1;i<=20;i++){ for (int j=1;j<=n*2;j++){ if (st[j][i-1]) st[j][i] = st[st[j][i-1]+1][i-1]; } } } voidchk(int x){ int cnt = 1,tmp = x; for (int i=20;i>=0;i--){ if (st[x][i]>=x && st[x][i]<tmp+n-1) x = st[x][i]+1,cnt+=(1<<i); } if (st[x][0]>=tmp+n-1) ans = min(ans,cnt); } intmain(){ ios::sync_with_stdio(false); cin.tie(0); while (cin>>n>>k){ int x,y; ans = 0x3f3f3f3f; s.clear(); for (int i=1;i<=k;i++){ cin>>x>>y; if (x>y) y+=n; l[i].l = x; l[i].r = y; } sort(l+1,l+1+k,cmp); int now = 1; for (int i=1;i<=n*2;i++){ while (l[now].l == i && now<=k){ s.insert(l[now].r); now++; } st[i][0] = 0; if (!s.empty()){ auto it = s.end(); it--; if (*it>=i) st[i][0] = *it; } } pre(); for (int i=1;i<=n;i++) chk(i); if (ans == 0x3f3f3f3f) cout<<"impossible"<<"\n"; else cout<<ans<<"\n"; for (int i=1;i<=2*n;i++) for (int j=1;j<=20;j++) st[i][j] = 0; } return0; }