#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MOD = 1e9 + 7, N = 2e3 + 10;
void solve() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());
  vector<long long> least_day;
  long long p = 0;
  for (long long i = 0; i < n; i++) {
    if (v[i].second >= p) {
      least_day.push_back(v[i].second);
      p = v[i].second;
    } else {
      least_day.push_back(v[i].first);
      p = v[i].first;
    }
  }
  cout << least_day[n - 1];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
