#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll INF = 1e18;
void solve() {
  ll n;
  cin >> n;
  set<ll> st;
  st.insert(INF);
  map<ll, set<pair<ll, ll>>> mp;
  rep(i, n) {
    ll l, r;
    cin >> l >> r;
    st.insert(l);
    mp[l].emplace(r, i);
  }
  ll ans = 0;
  while (st.size() > 1) {
    ans++;
    ll now = 0;
    for (;;) {
      ll nex = *st.lower_bound(now);
      if (nex == INF)
        break;
      auto iter = mp[nex].begin();
      now = iter->first;
      mp[nex].erase(iter);
      if (mp[nex].size() == 0)
        st.erase(nex);
    }
  }
  ans--;
  cout << ans << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}