#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, l, r;
  cin >> n;
  vector<pair<long long, long long> > v;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r;
    v.push_back(make_pair(l, -i));
    v.push_back(make_pair(r, i));
  }
  int c = 0;
  sort(v.begin(), v.end());
  set<long long> op;
  for (int i = 0; i < 2 * n; i++) {
    if (v[i].second < 0) {
      op.insert(-v[i].second);
    } else if (op.count(v[i].second)) {
      op.clear();
      c++;
    }
  }
  cout << c << endl;
  return 0;
}
