#include <bits/stdc++.h>
using namespace std;
struct Data {
  int num, io;
};
bool operator<(Data a, Data b) {
  return a.num != b.num ? a.num < b.num : a.io < b.io;
};
enum { IN = 1, OUT = -1 };
int main() {
  int N, a, b;
  cin >> N;
  vector<Data> list(N);
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    Data d1 = {a, IN};
    list.push_back(d1);
    Data d2 = {b, OUT};
    list.push_back(d2);
  }
  sort(list.begin(), list.end());
  int sum = 1, ans = 0;
  for (int i = 0; i < N * 2; i++) {
    sum += list[i].io;
    if (sum >= list[i].num) ans = max(ans, list[i].num);
  }
  cout << ans << endl;
}
