#include <bits/stdc++.h>
using namespace std;
struct data {
  long long ai, bi;
};
bool compare(data lhs, data rhs) {
  if (lhs.ai != rhs.ai) return lhs.ai < rhs.ai;
  return lhs.bi < rhs.bi;
}
inline void solve() {
  long long n;
  cin >> n;
  data D[n];
  for (long long i = 0; i < n; i++) {
    cin >> D[i].ai >> D[i].bi;
  }
  sort(D, D + n, compare);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (ans <= D[i].bi)
      ans = D[i].bi;
    else
      ans = D[i].ai;
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
