#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int arr[N + 1];
  memset(arr, 0, sizeof(arr));
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    if (a - 1 <= N) arr[a - 1]++;
    if (b <= N) arr[b]--;
  }
  int maxn = arr[0];
  int maxi = 0;
  for (int i = 1; i <= N; ++i) {
    arr[i] += arr[i - 1];
    if (arr[i] > maxn && arr[i] >= i) {
      maxn = arr[i];
      maxi = i;
    }
  }
  cout << maxi << endl;
}
