#include <bits/stdc++.h>
using namespace std;
long long abs(long long, long long);
void solve() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v;
  long long x, y;
  for (long long i = 0; i < n; i++) {
    cin >> x >> y;
    pair<long long, long long> p = make_pair(x, y);
    v.push_back(p);
  }
  sort(v.begin(), v.end());
  long long a = 0;
  for (long long i = 0; i < n; i++) {
    if (v[i].second >= a)
      a = v[i].second;
    else
      a = v[i].first;
  }
  cout << a << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
long long abs(long long a, long long b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
