// 请使用本地IDE(如DEV-CPP)运行无误后再将代码粘贴至此处并提交!
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
#define endl '\n'
const int N=2e6+10;
typedef long long ll;
ll ans=0,n1,m1;
ll t=0,s1=0,s2=0,s3=0,s4=0,max1=0,max2=0,min1=100000000,sum=10000000000000,n,m,i,j,k,l,r;
inline int read() {
bool sym=0;
int res=0;
char ch=getchar();
while(!isdigit(ch))sym |=(ch =='-'),ch=getchar();
while(isdigit(ch)) res =(res<<3)+(res<<1)+(ch^48),ch=getchar();
return sym ? -res : res;
}
void print(int x) {
if(!x)return;
print(x/10);
putchar(x%10+'0');
}
int isPrime(int n) {
float n_sqrt;
if(n==1) return 0;
if(n==2 || n==3) return 1;
if(n%6!=1 && n%6!=5) return 0;
n_sqrt=floor(sqrt((float)n));
for(int i=5; i<=n_sqrt; i+=6) {
if(n%(i)==0 | n%(i+2)==0) return 0;
}
return 1;
}
ll a[10006],low[10086];
struct node{
ll c,k;
}ss[100006];
ll cmp(node a,node b){
if(a.c ==b.c )
return a.k >b.k ;
return a.c >b.c ;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(i=1; i<=n; i++) {
cin>>ss[i].c >>ss[i].k ;
}
sort(ss+1,ss+1+n,cmp);
/*for(i=1;i<=n;i++)
cout<<ss[i].c <<" "<<ss[i].k <<endl;*/
for(i=1;i<=n;i++){
if(ss[i].k >low[ans])
low[++ans]=ss[i].k ;
else
{
ll ass=lower_bound(low+1,low+1+ans,ss[i].k )-low;
low[ass]=ss[i].k ;
}
}
cout<<ans;
return 0;
}
//mio lover
先按长度,宽度结构体排序,then 找宽度的最长上升子序列