#include <bits/stdc++.h>
using namespace std;
int x[111111];
int y[111111];
int main(void) {
  int i, n, m;
  int a, b;
  int res;
  cin >> n;
  res = m = 0;
  for (i = 1; i <= n; i++) {
    cin >> a >> b;
    x[a]++;
    x[b + 1]--;
    m = max(m, max(a, b));
  }
  m++;
  for (i = 1; i <= m; i++) {
    y[i] = x[i] + y[i - 1];
    if (y[i] >= i) res = max(res, i);
  }
  if (res == 0)
    cout << 0 << endl;
  else
    cout << res - 1 << endl;
  return 0;
}
