#include<stdio.h>
int main(){
int t,h,w,a1,b1,i,sum=0;
int a[1002],b[1002],c[1002];
scanf("%d",&t);
for(i=0;i<1000;i++){
a[i]=0;
b[i]=0;
c[i]=0;
}
while(t--){
scanf("%d%d",&h,&w);
if(h>w){
a1=w;
b1=h;
}
else if(h<=w){
a1=h;
b1=w;
}
for(i=0;i<1001;i++){
if(c[i]==0){
a[i]=a1;
b[i]=b1;
c[i]=1;
break;
}
if(a1<=a[i]&&b1<=b[i]&&c[i]!=0){
a[i]=a1;
b[i]=b1;
c[i]=1;
break;
}
}
}
for(i=0;i<1000;i++){
if(c[i]!=0)
sum+=1;
}
printf("%d\n",sum);
}