#include<stdio.h>
int main(){
int t,x;
int s;
int h,w;
int a[1010],b[1010],i,n=1;
for(i=1;i<=1009;i++){
a[i]=0;
b[i]=0;
}
scanf("%d",&t);
for(x=1;x<=t;x++){
scanf("%d %d",&h,&w);
for(i=1;i<=n;i++){
if((h<=a[i]&&w<=b[i])||(h<=b[i]&&w<=a[i])){
n=n;
a[i]=h;
b[i]=w;
s=1;
break;
}
else s=0;
}
if(s==0){
a[n]=h;
b[n]=w;
n=n+1;
}
}
printf("%d\n",n-1);
}