#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
typedef pair<string, string> pr;
int n;
const int maxn = 5005;
struct node{
int l, w;
}stick[maxn];
int sss[maxn], cnt = 0;
bool cmp(node a, node b)
{
return a.l > b.l;
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d%d", &stick[i].l, &stick[i].w);
}
sort(stick + 1, stick + 1 + n, cmp);
for(int i = 1; i <= n; i++){
if(stick[i].w > sss[cnt - 1]){
sss[cnt++] = stick[i].w;
}
else{
int pos = lower_bound(sss, sss + cnt, stick[i].w) - sss;
sss[pos] = stick[i].w;
}
}
printf("%d", cnt);
return 0;
}