#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, st, ed;
  int info[100100][2], total, lim;
  while (cin >> n) {
    total = 0;
    lim = 1;
    for (int i = 0; i < 100100; i++) info[i][0] = info[i][1] = 0;
    info[0][0] = info[1][0] = 1;
    for (int i = 0; i < n; i++) {
      cin >> st >> ed;
      lim = max(lim, ed);
      info[st][0]++;
      info[ed][1]++;
    }
    int ans = 0;
    for (int i = 1; i <= lim; i++) {
      if (info[i][0] != 0 && total + info[i][0] >= i) total += info[i][0];
      if (info[i][1] != 0 && total > i) {
        total -= info[i][1];
      }
      assert(total >= 0);
      ans = max(ans, total);
    }
    cout << ans - 1 << endl;
  }
  return 0;
}
