#include<stdio.h>
int main()
{
int t,a[1010][3],h,w,i,res=1;
scanf("%d",&t);
scanf("%d %d",&a[0][0],&a[0][1]);
int m=t-1;
while(m--){
int flag=0;
scanf("%d %d",&h,&w);
for(i=0;i<res;i++){
//printf("A[%d]%d-%d\n",i,a[i][0],a[i][1]);
if((h<=a[i][0]&&w<=a[i][1]) || (w<=a[i][0]&&h<=a[i][1])){
a[i][0]=w;
a[i][1]=h;
flag=1;
break;
}
}
if(!flag){
res++;
a[i][0]=w;
a[i][1]=h;
}
//printf("B[%d]%d-%d\n",i,a[i][0],a[i][1]);
}
printf("%d\n",res);
}