#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
const int N = 1e7 + 100, MOD = 1e9 + 7, INF = 1e9;
const long long bigINF = 1e18;
const double EPS = 1e-9;
long long n, a, b, rs;
vector<pair<long long, long long> > t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    t.push_back({a, b});
  }
  sort(t.begin(), t.end());
  for (int i = 0; i < n; ++i) {
    if (rs > t[i].second)
      rs = t[i].first;
    else
      rs = t[i].second;
  }
  cout << rs;
}
