#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1000 * 100;
int n, beg, en, ans;
pair<int, int> a[MAXn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  beg = a[0].first, en = a[0].second;
  for (int i = 1; i < n; i++) {
    if (a[i].second < en)
      ans++;
    else
      en = a[i].second;
  }
  cout << ans << endl;
}
