#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int n;
pair<int, int> p[5000];
int main() {
  cin >> n;
  for (int i = 0; i < (int)n; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = pair<int, int>(a, b);
  }
  sort(p, p + n);
  int mn = 0;
  for (int i = 0; i < (int)n; i++) {
    if (p[i].second >= mn)
      mn = p[i].second;
    else
      mn = p[i].first;
  }
  cout << mn << endl;
  return 0;
}
