#include <stdio.h>
int main() {
int n, h, w, num, r, i, j;
int a[1000][2];
scanf("%d", &n);
for(j = 0;j < n;j ++){
r = 0;
scanf("%d %d", &h, &w);
if(w > h) {
int t = w;
w = h;
h = t;
}
if(j == 0) {
a[0][0] = h;
a[0][1] = w;
num = 1;
}else {
for(i = 0;i < num;i ++) {
if(h <= a[i][0] && w <= a[i][1]) {
a[i][0] = h;
a[i][1] = w;
r = 1;
break;
}
}
if(r == 0){
a[num][0] = h;
a[num][1] = w;
num ++;
}
}
}
printf("%d\n", num);
return 0;
}