#include <bits/stdc++.h>
int main(void) {
  int n;
  std::cin >> n;
  int endmax = 0;
  int* pn = new int[100000];
  memset(pn, 0, 100000 * sizeof(int));
  for (int i = 0; i < n; i++) {
    int beg, end;
    std::cin >> beg >> end;
    for (int i = beg; i <= end; i++) pn[i]++;
    if (end > endmax) endmax = end;
  }
  int mps = 1;
  for (int i = 1; i <= endmax; i++) {
    if (pn[i] + 1 >= i) mps = i;
  }
  std::cout << (mps - 1) << '\n';
  return 0;
}
