#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 21;
int n;
long long now = -1, ans;
pair<int, int> seg[MAXN];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> seg[i].second >> seg[i].first;
  sort(seg, seg + n);
  for (int i = 0; i < n; i++) {
    if (seg[i].second >= now) {
      now = seg[i].first + 1;
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}
