#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long INF = 1e18 + 20;
const long long MOD = 1e9 + 7;
long long n, m, x, y, sum, cnt;
std::vector<pair<long long, long long>> v;
void solve() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> x >> y;
    v.push_back({x, y});
  }
  sort(v.begin(), v.end());
  for (auto i : v) {
    if (i.second >= cnt) {
      cnt = i.second;
    } else {
      cnt = i.first;
    }
  }
  cout << cnt << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) solve();
}
