#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
const int MAXE = 200500;
const int INF = 0x3f3f3f;
struct node {
  int s, e;
} x[MAXN];
bool cmp(node a, node b) {
  if (a.e == b.e) return a.s > b.s;
  return a.e < b.e;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) scanf("%d%d", &x[i].s, &x[i].e);
    sort(x, x + n, cmp);
    int ans = 0, now = 1;
    for (int i = 0; i < n; i++) {
      if (now <= x[i].s) {
        ans++;
        now = x[i].e + 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
