#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[500010];
bool cmp(const pair<int, int> lhs, const pair<int, int> rhs) {
  return lhs.second < rhs.second;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[i] = make_pair(x, y);
  }
  sort(a, a + n, cmp);
  int cnt = 0, cur = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].first > cur) {
      cnt++;
      cur = a[i].second;
    }
  }
  cout << cnt << "\n";
  return 0;
}
