#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > data(n);
  vector<pair<int, pair<int, int> > > borders(2 * n);
  for (long long i = 0; i < n; ++i) {
    cin >> data[i].first >> data[i].second;
    borders[2 * i].first = data[i].first;
    borders[2 * i].second = make_pair(1, i);
    borders[2 * i + 1].first = data[i].second;
    borders[2 * i + 1].second = make_pair(-1, i);
  }
  sort(borders.begin(), borders.end());
  set<int> st;
  set<int> cor;
  int cnt = 0;
  int res = 0;
  for (long long i = 0; i < 2 * n; ++i) {
    if (borders[i].second.first == 1) {
      st.insert(borders[i].second.second);
      cor.insert(borders[i].first);
      continue;
    }
    int t = borders[i].second.second;
    int k = data[t].first;
    int tmp = *cor.begin();
    cor.erase(k);
    if (tmp < k) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
