#include <stdio.h>
int main() {
int n,a,b,ra[1000]={0},rb[1000]={0},i,j,cnt=1;
scanf("%d",&n);
scanf("%d%d",&a,&b);
ra[1] = a;
rb[1] = b;
for(i=1;i<n;i++){
scanf("%d%d",&a,&b);
for(j=1;j<=cnt;j++){
if((a<=ra[j]&&b<=rb[j])||(a<=rb[j]&&b<=ra[j])){
ra[j] = a;
rb[j] = b;
break;
}
}
if(j==cnt+1){
cnt++;
ra[cnt] = a;
rb[cnt] = b;
}
}
printf("%d",cnt);
}