#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > p;
int main() {
  int n;
  p.clear();
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    p.push_back(make_pair(a, b));
  }
  sort(p.begin(), p.end());
  int ma = 0;
  for (int i = 0; i < n; ++i)
    if (p[i].second >= ma)
      ma = p[i].second;
    else
      ma = p[i].first;
  printf("%d\n", ma);
}
