#include <bits/stdc++.h>
using namespace std;
struct event {
  long long start, end;
};
bool compare(const event &first, const event &second) {
  return first.start < second.start;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cout.tie(0);
  ;
  int n;
  cin >> n;
  int i;
  event a[n];
  for (i = 0; i < n; i++) cin >> a[i].start >> a[i].end;
  sort(a, a + n, compare);
  int counter = 0;
  int j;
  long long currentNumber = a[0].end;
  for (i = 1; i < n; i++) {
    if (a[i].end < currentNumber)
      counter++;
    else
      currentNumber = a[i].end;
  }
  cout << counter << "\n";
}
