#include <bits/stdc++.h>
int N;
std::vector<int> imos;
int main() {
  std::cin >> N;
  imos.resize(N + 2, 0);
  for (long i = 0; i < (N); ++i) {
    int a, b;
    std::cin >> a >> b;
    ++imos[a];
    --imos[b];
  }
  int x = 0, ans = 0;
  for (int i = 0; i <= N + 1; ++i) {
    x += imos[i];
    if (x + 1 >= i) {
      ans = i - 1;
    }
  }
  std::cout << ans << std::endl;
}
