#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int N;
int a[MAXN], b[MAXN];
int main() {
  while (cin >> N) {
    map<int, int> m;
    for (int i = 0; i < N; ++i) {
      cin >> a[i] >> b[i];
      m[a[i]]++;
      m[b[i]]--;
    }
    int res = 1, num = 1;
    vector<int> t, x;
    for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
      num += it->second;
      if (num >= it->first) {
        res = max(res, num);
      }
    }
    cout << res - 1 << endl;
  }
  return 0;
}
