#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
const int maxn=1e4+5;
int a[maxn],b[maxn],n,m;
int main()
{
int t,i;
cin>>t>>a[0]>>b[0];
t--;
int l=1;
while(t--)
{
scanf("%d%d",&n,&m);
for(i=0;i<l;++i)
{
if((n<=a[i]&&m<=b[i])||(n<=b[i]&&m<=a[i]))
{
a[i]=n;
b[i]=m;
break;
}
}
if(i==l)
{
a[l]=n;
b[l++]=m;
}
}
printf("%d",l);
}