#include <bits/stdc++.h>
using namespace std;
int N, a[100010], b[100010];
bool check(int m) {
  int cnt = 0;
  for (int i = 0; i < N; i++)
    if (a[i] <= m && m <= b[i]) cnt++;
  if (cnt + 1 < m)
    return false;
  else
    return true;
}
int main(void) {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  int l = 1, r = N + 2;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check(m))
      l = m;
    else
      r = m;
  }
  cout << l - 1 << endl;
  return 0;
}
