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