//#define local
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#define MAXN 5005
using namespace std;
typedef long long ll;
struct size{
int l,w;
size(int l=0,int w=0):l(l),w(w){
}
bool operator < (const size &t) const{
if(l!=t.l)
return l>t.l;
else
return w>=t.w;
}
};
vector<size>g;//n(不严格下降极大子序列)=l(最长严格上升序列 )
int n;
int main(){
#ifdef local
freopen("data.in","rb",stdin);
//freopen("data.out","wb",stdout);
#endif
scanf("%d",&n);
for(int i=0;i<n;++i){
int ll,ww;
scanf("%d%d",&ll,&ww);
g.push_back(size(ll,ww));
}
sort(g.begin(),g.end());
vector<int>d;
d.push_back(g[0].w);
for(int i=1;i<n;++i){
int next=g[i].w;
if(next>d.back())
d.push_back(next);
else{
vector<int>::iterator it=lower_bound(d.begin(),d.end(),next);
d[it-d.begin()]=next;
}
}
cout<<d.size();
return 0;
}