#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
int main(void) {
  int p;
  cin >> p;
  vi d(100002, 0);
  for (int lp = 0; lp < p; lp++) {
    int a, b;
    cin >> a >> b;
    d[a]++, d[b + 1]--;
  }
  int ans = 0;
  for (int i = 1; i < 100002; i++) {
    d[i] += d[i - 1];
    if (d[i] >= i) ans = i;
  }
  cout << ans - 1 << endl;
}
