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