#include #include #include using namespace std; typedef long long lint; typedef vectorvi; typedef pairpii; #define rep(i,n)for(int i=0;i<(int)(n);++i) int main(){ int n; cin>>n; vi l(n),r(n); rep(i,n)cin>>l[i]>>r[i]; int ml=0; vectorm(n+1); rep(i,n){ int p=0,f=ml+1; while(f-p>1){ int x=(f+p)/2; pii cur=m[x]; if(max(l[i],cur.second+1)<=r[i]) p=x; else f=x; } ml=max(ml,p+1); //UPDATE m[p+1]=pii(i,max(l[i],m[p].second+1)); } cout<