#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b;
} st[500010];
bool cmp(node i, node j) { return i.b < j.b; }
int main() {
  int i, n;
  while (~scanf("%d", &n)) {
    for (i = 0; i < n; i++) {
      scanf("%I64d%I64d", &st[i].a, &st[i].b);
    }
    sort(st, st + n, cmp);
    int x = st[0].b, count = 1;
    for (i = 1; i < n; i++) {
      if (st[i].a > x) {
        x = st[i].b;
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}
