#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b, ans;
  int max = 0;
  int man[100001];
  for (int i = 0; i < 100001; i++) {
    man[i] = 0;
  }
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    for (int j = a; j <= b; j++) man[j]++;
  }
  for (int i = 0; i < N; i++) {
    if (man[i] > max && man[i] >= i - 1) {
      max = man[i];
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
