#include<stdio.h>
#include<string.h>
#include<math.h>
#define PI 3.141592
int a[1000];
int b[1000];
int main (void) {
int i,n,h,k,ans=0;
a[0]=b[0]=0;
scanf("%d",&n);
while(n--) {
scanf("%d %d",&h,&k);
for (i=0; i<=ans; i++) {
if (h<=a[i]&&k<=b[i]) {
a[i]=h;
b[i]=k;
break;
} else if (h<=b[i]&&k<=a[i]) {
b[i]=h;
a[i]=k;
break;
}
}
if (i>ans) {
a[ans]=h;
b[ans]=k;
ans++;
}
}
printf("%d",ans);
}