#include <bits/stdc++.h>
using namespace std;
int a, b;
std::vector<pair<int, int> > v;
int main() {
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  int st = v[0].first;
  int end = v[0].second;
  int cnt = 0;
  for (int i = 1; i < v.size(); ++i) {
    int x = v[i].first;
    int y = v[i].second;
    if (x == st && y > end) {
      end = y;
    } else if (x > st && y < end) {
      cnt++;
    } else if (x > st && y > end) {
      st = x;
      end = y;
    }
  }
  cout << cnt << endl;
  return 0;
}
