#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
const int N = 5010;
int n;
PII city[N];
int f[N];
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d%d", &city[i].first, &city[i].second);
//swap(city[i].first, city[i].second);
}
sort(city, city + n);
int res = 0;
for(int i = 0; i < n; i++)
{
f[i] = 1;
for(int j = 0; j < i; j++)
{
if(city[i].second > city[j].second)
{
f[i] = max(f[i], f[j] + 1);
}
}
res = max(res, f[i]);
}
printf("%d\n", res);
return 0;
}
/*
有点难度,需要排序才可以知道是最长上升子序列模型
按first或second排序都可以
*/