#include <bits/stdc++.h>
const double eps = 1e-10;
using namespace std;
const int NN = 21;
const int MM = 151;
const int need = (1 << 30) - 1;
int N, M;
string in[55];
int i, j, p;
pair<int, int> shedl[5555];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    shedl[i].first = a;
    shedl[i].second = b;
  }
  sort(shedl, shedl + N);
  for (int i = 0; i < N; i++) {
    if (shedl[i].second >= p) {
      p = shedl[i].second;
    } else {
      p = shedl[i].first;
    }
  }
  cout << p << endl;
  return 0;
}
