#include<stdio.h>
int main()
{
int i,n,h,w,s=1,f;
int hm[1001]={2147483647},wm[1001]={2147483647};
scanf("%d",&n);
while(n--)
{
scanf("%d %d",&h,&w);
f=0;
for(i=1;i<=s;i++)
{
if(h<=hm[i]&&w<=wm[i])
{
hm[i]=h;
wm[i]=w;
f=1;
break;
}
else if(h<=wm[i]&&w<=hm[i])
{
hm[i]=w;
wm[i]=h;
f=1;
break;
}
}
if(f==0)
{
s++;
hm[s]=h;
wm[s]=w;
}
}
printf("%d\n",s-1);
}