#include <bits/stdc++.h>
int n, a, b, friends[100005], ans, maxn, ansi;
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  for (int i = 0; i < (n); ++i) {
    std::cin >> a >> b;
    if (a > n + 1) {
      maxn++;
      continue;
    } else if (b > n + 1 - maxn) {
      b = n + 1 - maxn;
    }
    for (int i = a; i <= b; ++i) friends[i]++;
  }
  for (int i = 0; i < (n + 1); ++i) {
    if (ansi < friends[i]) {
      ans = i - 1;
    }
  }
  std::cout << ans << std::endl;
}
