#include <iostream>
#include <cstdio>
using namespace std;
void swap(int& a,int& b)
{
int temp;
temp=a;
a=b;
b=temp;
}
int maxint(int a,int b)
{
if (a>b)
return(a);
return(b);
}
int main(void)
{
freopen("active.in","r",stdin);
freopen("active.out","w",stdout);
int i,j,n,a[1010]={-1},b[1010]={-1},c[1010]={0},maxnum=0;
cin>>n;
for (i=1;i<=n;i++)
cin>>a[i]>>b[i];
for (i=1;i<n;i++)
for (j=1;j<=n-i;j++)
if (b[j]>b[j+1])
{
swap(a[j],a[j+1]);
swap(b[j],b[j+1]);
}
for (i=1;i<=n;i++)
{
for (j=i-1;j>=0;j--)
if (a[i]>b[j])
c[i]=maxint(c[i],c[j]+1);
maxnum=maxint(maxnum,c[i]);
}
cout<<maxnum<<endl;
return(0);
}