#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
int x,y;
}a[6000];
int i,j,k,n,m,p;
int f[6000];
int tail;
bool cmp(node a,node b){
if (a.x>b.x) return false;else{
if (a.x<b.x) return true;else{
return (a.y<b.y);
}
}
}
int main()
{
freopen("wooden.in","r",stdin);
freopen("wooden.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+n+1,cmp);
f[1]=a[1].y;
tail=1;
for (i=2;i<=n;i++){
int minx=200000000;
for (j=1;j<=tail;j++){
if (f[j]<a[1].y)
if (f[j]>minx){
minx=f[j];
p=j;
}
if (minx==200000000){
tail++;
f[tail]=a[i].y;
}else{
f[j]=a[i].y;
}
}
}
printf("%d",tail);
return 0;
}