#include<bits/stdc++.h>
#define maxn 50050
using namespace std;
int f[maxn],a[maxn],b[maxn];
struct edge{
int begin;
int end;
}e[maxn];
bool cmp(edge a,edge b)
{
return a.begin<b.begin;
}
int main()
{
int n;
int ans=-1;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>e[i].begin>>e[i].end;
}
sort(e+1,e+1+n,cmp);
for(int i=1;i<=n;i++)
{
f[i]=1;
for(int j=1;j<i;j++)
{
if(e[i].end>=e[j].end&&f[i]<f[j]+1)
{
f[i]=f[j]+1;
}
}
ans=max(ans,f[i]);
}
cout<<ans;
}