#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[200200];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[2 * i].first = x;
    a[2 * i].second = i + 1;
    a[2 * i + 1].first = y;
    a[2 * i + 1].second = -i - 1;
  }
  sort(a, a + 2 * n);
  int res = 0, cur = 0;
  map<int, int> itos, stoi;
  for (int i = 0; i < 2 * n; i++)
    if (a[i].second > 0) {
      int idx = a[i].second;
      itos[idx] = a[i].first;
      stoi[a[i].first] = idx;
    } else {
      int idx = -a[i].second;
      if (stoi.begin()->second != idx) res++;
      stoi.erase(itos[idx]);
      itos.erase(idx);
    }
  cout << res << endl;
  return 0;
}
