#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int maxn = 2000100;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  int ans = 0;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  sort(v.begin(), v.end());
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    if (v[i].second < x and v[i].first > y) ans++;
    x = max(v[i].second, x);
    y = max(v[i].first, y);
  }
  cout << ans << "\n";
  return 0;
}
