#include <bits/stdc++.h>
bool debug = true;
int N;
std::vector<int> cnt(100005, 0);
int main() {
  std::cin >> N;
  int a, b;
  for (long i = 0; i < (N); ++i) {
    std::cin >> a >> b;
    for (auto i = (a); i < (b + 1); ++i) {
      ++cnt[i];
    }
  }
  int ans = 0;
  for (auto i = (2); i < (100002); ++i) {
    if (i - 1 <= cnt[i]) {
      ans = i - 1;
    }
  }
  std::cout << ans << std::endl;
}
