#include<bits/stdc++.h>
using namespace std;
struct MT{
int l,w;
}mt[5003];
int n;
int d[5003];
bool vis[5003];
int len = 0,res = 0;
bool cmp(MT &a,MT &b)
{
if(a.l == b.l)return a.w > b.w;
else return a.l > b.l;
}
int main()
{
cin >> n;
for(int i = 1;i <= n;i++)
cin >> mt[i].l >> mt[i].w;
sort(mt+1,mt+1+n,cmp);
for(int i = 1;i <= n;i++)
{
if(d[res] < mt[i].w)d[++res] = mt[i].w;
else *(upper_bound(d+1,d+1+res,mt[i].w,less<int>())) = mt[i].w;
}
cout << res;
return 0;
}