POJ 1769//sep9 #include <iostream> using namespace std;
const int maxn=100012;
const int maxx=9999999;
int n,m;
int minv[maxn*4];
void build (int l,int r,int k) {Minv[k]=maxx;
if (l==r) return;
int m= (L+R)/2;
Build (L,m,2*k);
Build (m+1,r,2*k+1);
} void Update (int i,int v,int k,int l,int R) {if (minv[k]>v) minv[k]=v;
if (l==r) {return;
} int m= (L+R)/2;;
if (i<=m) update (I,V,2*K,L,M);
else update (I,V,2*K+1,M+1,R);
} int query (int from,int to,int k,int l,int R) {if (from<=l&&r<=to) return minv[k];
int m= (L+R)/2;;
if (to<=m) return query (FROM,TO,2*K,L,M);
else if (from>m) return query (FROM,TO,2*K+1,M+1,R);
else return min (query (from,to,2*k,l,m), query (From,to,2*k+1,m+1,r));
} int main () {scanf ("%d%d", &n,&m);
Build (1,n,1);
Update (1,0,1,1,N);
while (m--) {int s,t;
scanf ("%d%d", &s,&t);
if (s>=t) continue; int end=n;//n = t-1,t,... n all acceptable int v=query (s, end,1,1,n);
Update (T,V+1,1,1,N);
} printf ("%d\n", Query (N,n,1,1,n)); }