#include <bits/stdc++.h>
using namespace std;
struct code {
  int x, y;
};
bool comp(code a, code b) { return a.y < b.y or (a.y == b.y and a.x < b.x); }
code a[1000001];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].x);
    scanf("%d", &a[i].y);
  }
  sort(a + 1, a + n + 1, comp);
  int last = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i].x > last) {
      last = a[i].y;
      cnt++;
    }
  }
  cout << cnt;
}
