#include <stdio.h>
int main() {
int n,h[1000],w[1000],h1,w1,r=1;
scanf("%d",&n);
scanf("%d %d",&h[r],&w[r]);
n--;
while(n--) {
int is=0;
scanf("%d %d",&h1,&w1);
for(int j=1;j<=r;j++) {
if((h1<=h[j]&&w1<=w[j])||(w1<=h[j]&&h1<=w[j])) {
h[j]=h1;
w[j]=w1;
is=1;
break;
}
}
if(is==0) {
r++;
h[r]=h1;
w[r]=w1;
}
}
printf("%d\n",r);
return 0;
}