#include <bits/stdc++.h>
using namespace std;
int n;
struct examd {
  int a, b;
};
examd ex[5001];
bool cmp(examd x, examd y) {
  if (x.a != y.a) return x.a < y.a;
  return x.b < y.b;
}
void Citire() {
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) cin >> ex[i].a >> ex[i].b;
}
int main() {
  int i;
  Citire();
  sort(ex + 1, ex + n + 1, cmp);
  int prev;
  prev = ex[1].b;
  for (i = 2; i <= n; i++) {
    if (prev <= ex[i].b)
      prev = ex[i].b;
    else
      prev = ex[i].a;
  }
  cout << prev << "\n";
  return 0;
}
