#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
const int INF = 999999999;
struct Order {
  int st;
  int ed;
} ord[maxn];
Order flow[maxn];
bool cmp(const Order& a, const Order& b) { return a.ed < b.ed; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &ord[i].st, &ord[i].ed);
  }
  sort(ord, ord + n, cmp);
  flow[0] = ord[0];
  int k = 1;
  for (int i = 1; i < n; i++) {
    if (flow[k - 1].ed < ord[i].st) {
      flow[k++] = ord[i];
    }
  }
  cout << k << endl;
}
