#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
const double pi = acos(-1.0);
const double eps = 1e-7;
template <class TT>
TT sqr(TT a) {
  return a * a;
}
template <class TT>
TT abs(TT a) {
  if (a < 0) return -a;
  return a;
}
template <class ZZ>
ZZ max(ZZ a, ZZ b, ZZ c) {
  return max(a, max(b, c));
}
template <class ZZ>
ZZ min(ZZ a, ZZ b, ZZ c) {
  return min(a, min(b, c));
}
vector<pair<int, int> > v;
int main() {
  int i, j, k, l, tks, ks = 1, n, m;
  pair<int, int> a;
  while (scanf("%d", &n) == 1) {
    v.clear();
    for (i = 0; i < n; i++) {
      scanf("%d%d", &a.first, &a.second);
      v.push_back(a);
    }
    sort((v).begin(), (v).end());
    int ind = 0;
    for (int i = 0; i < n; i++) {
      if (ind <= v[i].second)
        ind = v[i].second;
      else
        ind = v[i].first;
    }
    cout << ind << endl;
  }
  return 0;
}
