#include <bits/stdc++.h>
using namespace std;
struct rest {
  int s, f;
};
rest lis[1000500];
bool cmp(rest &a, rest &b) { return a.f < b.f; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &lis[i].s, &lis[i].f);
  }
  sort(lis + 1, lis + n + 1, cmp);
  int now = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    if (lis[i].s > now) {
      ans++;
      now = lis[i].f;
    }
  }
  cout << ans << endl;
}
