#include <bits/stdc++.h>
using namespace std;
const long INF = 1000000000;
int main() {
  long n;
  vector<pair<long, long> > v;
  long a, b;
  cin >> n;
  for (long i = 0; i < n; ++i) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  long ans = 0;
  for (long i = 0; i < n; ++i) {
    if (v[i].second >= ans)
      ans = v[i].second;
    else
      ans = v[i].first;
  }
  cout << ans << endl;
  return 0;
}
