#include <bits/stdc++.h>
int n, a, b, friends[100005], fri, maxi;
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;
    a--;
    b--;
    for (int i = a; i <= b; ++i) friends[i]++;
  }
  for (int i = 0; i < (n + 1); ++i) {
    if (fri <= friends[i] && friends[i] >= i) {
      fri = friends[i];
      maxi = i;
    }
  }
  std::cout << maxi << std::endl;
  return 0;
}
