#include<stdio.h>
int main(){
int n,i,j,c,k,num=1,cl[1001]={0},kl[1001]={0};
scanf("%d",&n);
for(j=0;j<n;j++){
scanf("%d %d",&c,&k);
for(i=0;i<num;i++){
if(j==0){
cl[0]=c;kl[0]=k;
}else if((c<=cl[i]&&k<=kl[i])||(c<=kl[i]&&k<=cl[i])){
cl[i]=c;kl[i]=k;
break;
}else if(i==num-1&&(!(c<=cl[i]&&k<=kl[i])||(c<=kl[i]&&k<=cl[i]))){
num++;
cl[num-1]=c;kl[num-1]=k;
break;
}
}
}
printf("%d\n",num);
}