#include<stdio.h>
int main()
{
int n,h[1010],w[1010],ans=1,t,i,j,h1[1010],w1[1010];
scanf("%d",&n);
for(i=0;i<n;++i)
{
scanf("%d %d",&h[i],&w[i]);
}
h1[0]=h[0];
w1[0]=w[0];
for(i=1;i<n;++i)
{
t=0;
for(j=0;j<ans;++j)
{
if((h[i]<=h1[j]&&w[i]<=w1[j])||(h[i]<=w1[j]&&w[i]<=h1[j]))
{
h1[j]=h[i];
w1[j]=w[i];
break;
}
else
{
t++;
}
}
if(t==ans)
{
ans++;
h1[ans-1]=h[i];
w1[ans-1]=w[i];
}
}
printf("%d\n",ans);
}