#include<stdio.h>
#include<math.h>
int main(){
int n,x,y,sum=1,a,b,c[1000],d[1000],i;
scanf("%d",&n);
n=n-1;
scanf("%d%d",&x,&y);
c[0]=x;
d[0]=y;
while(n--)
{
int z=0;
scanf("%d%d",&a,&b);
for(i=0;i<sum;++i){
if((a<=c[i]&&b<=d[i])||(a<=d[i]&&b<=c[i])){
c[i]=a;
d[i]=b;
z=1;
break;
}
}
if(z==0){
c[i]=a;
d[i]=b;
sum++;
}
}
printf("%d",sum);
return 0;
}