#include <bits/stdc++.h>
using namespace std;
struct habijabi {
  long int start_time, end_time;
} work[500500];
bool cmp(habijabi a, habijabi b) {
  if (a.end_time == b.end_time) {
    return a.start_time < b.start_time;
  }
  return a.end_time < b.end_time;
}
int main() {
  long int t, n, i, j;
  scanf("%ld", &n);
  for (i = 0; i < n; i++) {
    scanf("%ld %ld", &work[i].start_time, &work[i].end_time);
  }
  sort(work, work + n, cmp);
  int ans = 0, prev_end = -1;
  for (i = 0; i < n; i++) {
    if (work[i].start_time > prev_end) {
      ans++;
      prev_end = work[i].end_time;
    }
  }
  printf("%d\n", ans);
  return 0;
}
