#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 1e9;
const int mod = 1e9 + 7;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n;
  cin >> n;
  pair<int, int> p[n];
  for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
  sort(p, p + n);
  int ans = 0;
  pair<int, int> tmp = p[0];
  for (int i = 1; i < n; i++) {
    if (p[i].first >= tmp.second || p[i].second > tmp.second) {
      tmp = p[i];
    } else if (p[i].first >= tmp.first && p[i].second <= tmp.second)
      ans++;
  }
  cout << ans << '\n';
  return 0;
}
