#include <stdio.h>
#include <string.h>
int main()
{
int n,i,j;
scanf("%d",&n);
int h,w,h1,w1,k=0,sum=1,kk=0;
int a[10011];
while(n--)
{
scanf("%d%d",&h,&w);
if(kk==0)
{
a[k]=h;
a[k+1]=w;
k=k+2;
kk++;
goto ha;
}
for(i=0;i<k;i=i+2)
{
if((a[i]>=h&&a[i+1]>=w)||(a[i+1]>=h&&a[i]>=w))
{
a[i]=h;
a[i+1]=w;
goto ha;
}
}
a[k]=h;
a[k+1]=w;
k=k+2;
sum++;
ha:;
}
printf("%d\n",sum);
return 0;
}