#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, a, b;
  cin >> n;
  vector<pair<long long, long long> > v;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  bool flag = 0;
  long long ans = v[0].second;
  for (int i = 0; i < n; i++) {
    if (v[i].second >= ans)
      ans = v[i].second;
    else
      ans = v[i].first;
  }
  cout << ans << '\n';
  return 0;
}
