#include <bits/stdc++.h>
template <class T, class S>
void cmin(T &a, const S &b) {
  if (a > b) a = b;
}
template <class T, class S>
void cmax(T &a, const S &b) {
  if (a < b) a = b;
}
using namespace std;
int main() {
  int imos[1000000] = {0};
  int gotiusa;
  cin >> gotiusa;
  int range = 0;
  vector<pair<int, int> > v;
  for (int i = 0; i < gotiusa; i++) {
    int tiya, rize;
    cin >> tiya >> rize;
    imos[tiya]++;
    imos[rize]--;
    cmax(range, rize + 1);
    v.push_back(pair<int, int>(tiya, rize));
  }
  for (int _ = 0; _ < 100000; _++)
    if (_) imos[_] += imos[_ - 1];
  int ans = 0;
  for (int i = 0; i < v.size(); i++)
    if (v[i].first <= imos[v[i].first] && v[i].second >= imos[v[i].second])
      ans++;
  cout << ans << endl;
}
