#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<long long int, long long int> > v;
  long long int n, x, c = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  long long int i = 0;
  x = v[0].second;
  while (i < n) {
    if (v[i].first <= x) i++;
    if (v[i].second < x) x = v[i].second;
    if (v[i].first > x || i >= n) {
      c++;
      x = v[i].second;
    }
  }
  cout << c;
}
