#include<stdio.h>
#include<string.h>
int main(void)
{
int n,i,c[1001],k[1001],sum,p[1003],j,flag;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&c[i],&k[i]);
}
sum=1;p[1]=0;
for(i=1;i<n;i++)
{
flag=0;
for(j=1;j<=sum;j++)
{
if(c[i]<=c[p[j]]&&k[i]<=k[p[j]]&&flag==0){p[j]=i;flag=1;}
else if(c[i]<=k[p[j]]&&k[i]<=c[p[j]]&&flag==0){p[j]=i;flag=1;}
else if(j==sum&&flag==0) {sum++;p[sum]=i;}
}
}
printf("%d\n",sum);
}