#include <bits/stdc++.h>
using namespace std;
int dp[500010];
int main() {
  int t;
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  vector<int> starts;
  for (int i = 0; i < n; i++) {
    int aa, bb;
    scanf("%d %d", &aa, &bb);
    v.push_back(make_pair(aa, bb));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    starts.push_back(v[i].first);
  }
  dp[n] = 0;
  for (int i = n - 1; i >= 0; i--) {
    dp[i] = dp[i + 1];
    vector<int>::iterator it;
    it = upper_bound(starts.begin(), starts.end(), v[i].second);
    int pos = it - starts.begin();
    dp[i] = max(dp[i], 1 + dp[pos]);
  }
  cout << dp[0] << endl;
  return 0;
}
