#include <bits/stdc++.h>
using namespace std;
struct tim {
  long long int a;
  long long int b;
};
bool comp(tim &x, tim &y) {
  if (x.a == y.a) return x.b <= y.b;
  return x.a < y.a;
}
int main() {
  long long int n, a1, b1, t;
  cin >> n;
  tim *arr = new tim[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a1 >> b1;
    arr[i].a = a1;
    arr[i].b = b1;
  }
  sort(arr, arr + n, comp);
  t = arr[0].b;
  for (long long int i = 1; i < n; i++) {
    if (t <= arr[i].b) {
      t = arr[i].b;
    } else {
      t = arr[i].a;
    }
  }
  cout << t << "\n";
  delete[] arr;
}
