#include #include using namespace std; multiset S; int main() { int N; scanf ("%d",&N); while (N--) { int x,y; scanf ("%d %d",&x,&y); auto I = S.upper_bound(y); if (I != S.end()) S.erase(I); S.insert(x+1); } printf ("%d\n",S.size()); return 0; }