#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > pii;
  int rui[100010] = {};
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a -= 2;
    b -= 2;
    rui[a]++;
    rui[b + 1]--;
  }
  int ma = 0;
  int now = 0;
  for (int i = 0; i < n + 1; i++) {
    now += rui[i];
    if (now > i) ma = max(ma, now);
  }
  cout << ma << endl;
  return 0;
}
