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