#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;
cin>>n;
int p[2][1005],s[2][1005];
int a,b,date=0,minn,maxx;
for(int i=0;i<n;i++){
scanf("%d%d",&a,&b);
int fff=0;
minn=min(a,b);maxx=max(a,b);
for(int j=1;j<=date;j++){
if(minn<=s[0][j]&&maxx<=s[1][j]){
fff=1;
s[0][j]=minn;s[1][j]=maxx;
break;
}
}
if(!fff){
date++;
s[0][date]=minn;s[1][date]=maxx;
}
}
printf("%d",date);
return 0;
}