#include <bits/stdc++.h>
using namespace std;
template <class T>
inline std::string to_string(const T& t) {
  std::stringstream ss;
  ss << t;
  return ss.str();
}
int n, a, b, f, mx = 0;
vector<pair<int, int> > v;
int main() {
  std::ios_base::sync_with_stdio(false);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  int chk = v[0].second;
  for (int i = 1; i <= n - 1; i++) {
    if (v[i].second >= chk) {
      chk = v[i].second;
    } else {
      chk = v[i].first;
    }
  }
  cout << chk << endl;
  return 0;
}
