#include <bits/stdc++.h>
using namespace std;
struct a {
  long long x, y;
};
a p[500005];
bool cmp(a q, a w) {
  if (q.y == w.y)
    return q.x < w.x;
  else
    return q.y < w.y;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
  sort(p, p + n, cmp);
  long long ans = 0, flag = -1 << 9;
  for (int i = 0; i < n; i++) {
    if (p[i].x > flag) {
      ans++;
      flag = p[i].y;
    } else
      continue;
  }
  cout << ans << endl;
}
