#include <algorithm>
#include <iostream>
#include<vector>
#include<cstring>
using namespace std;
int main() {
int n;
cin >> n;
int f[n];
vector<pair<int, int>> e(n);
for(int i = 0; i < n; i ++) cin >> e[i].first >> e[i].second;
sort(e.begin(), e.end(),[](const pair<int, int>& a, const pair<int, int>& b){
if(a.first == b.first) return a.second > b.second;
return a.first < b.first;
});
e.erase(unique(e.begin(),e.end()), e.end());
n = e.size();
for(int i = 0; i < n; i ++) f[i] = 1;
int maxN = 1;
for(int i = 1; i < n; i ++){
for(int j = 0; j < i; j ++){
if(e[j].second < e[i].second)
f[i] = max(f[j] + 1, f[i]);
}
if(f[i] > maxN) maxN = f[i];
}
cout << maxN << endl;
return 0;
}