#include <bits/stdc++.h>
using namespace std;
int main() {
  int n(0);
  cin >> n;
  assert(cin && n >= 1);
  int ans = 0;
  map<int, int> vs;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    assert(cin && a >= 1 && a < b);
    pair<map<int, int>::iterator, bool> p = vs.insert(make_pair(a, b));
    assert(p.second);
    map<int, int>::iterator const it = p.first;
    if (it != vs.begin()) {
      map<int, int>::iterator itPrev = it;
      --itPrev;
      assert(itPrev->first < a);
      if (itPrev->second > b) {
        vs.erase(it);
        ++ans;
        continue;
      }
    }
    map<int, int>::iterator it1(it);
    ++it1;
    for (map<int, int>::iterator itE(vs.end()); it1 != itE;) {
      int A = it1->first, B = it1->second;
      assert(a < A);
      if (b > B) {
        map<int, int>::iterator it1Next = it1;
        ++it1Next;
        vs.erase(it1);
        ++ans;
        it1 = it1Next;
      } else {
        break;
      }
    }
  }
  assert(n == ans + vs.size());
  cout << ans;
  return 0;
}
