#include <bits/stdc++.h>
using namespace std;
long long n, m, k, t = 1, x, y, z, l, r, w, q, ct = 0, ans = 0, f = 0;
string s, p;
long long a[200005];
set<long long> si;
queue<long long> qi;
map<long long, long long> mi;
vector<long long> vi;
priority_queue<long long> pqdi;
priority_queue<long long, vector<long long>, greater<long long>> pqai;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  cin >> n;
  vector<pair<long long, long long>> vi;
  for (long long i = 1; i <= n; i++) {
    cin >> x >> y;
    vi.push_back({x, y});
  }
  sort(vi.begin(), vi.end());
  for (long long i = 0; i < n; i++) {
    if (vi[i].second >= ans)
      ans = vi[i].second;
    else
      ans = vi[i].first;
  }
  cout << ans;
}
