#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<int> > b(n, vector<int>(2)), e(n, vector<int>(2));
  for (int i = 0; i < n; i++) {
    cin >> b[i][0] >> e[i][0];
    b[i][1] = i;
    e[i][1] = i;
  }
  sort(b.begin(), b.end());
  sort(e.begin(), e.end());
  vector<int> bi(n);
  for (int i = 0; i < n; i++) {
    bi[b[i][1]] = i;
  }
  int k = 0;
  vector<bool> v(n, 0);
  int m = 0;
  for (int i = 0; i < n; i++) {
    if (bi[e[i][1]] > m) k++;
    v[bi[e[i][1]]] = 1;
    while (m < n && v[m]) m++;
  }
  cout << k << endl;
}
