#include <iostream>
#include <algorithm>
using namespace std;
const int N = 5010;
pair<int, int> a[N];
int n, f[N], res;
int main()
{
cin >> n;
for ( int i = 0; i < n; i ++ ) cin >> a[i].first >> a[i].second;
sort(a, a + n);
for ( int i = 0; i < n; i ++ )
{
f[i] = 1;
for ( int j = 0; j < i; j ++ )
if ( a[i].second > a[j].second )
f[i] = max(f[i], f[j] + 1);
res = max(res, f[i]);
}
cout << res;
return 0;
}