#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 30, N = 1e5 + 10;
const long double PI = acos(0.0) * 2;
vector<pair<int, int> > v;
int n, a, b, last;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  last = v[0].second;
  for (int i = 1; i < n; ++i) {
    if (last <= v[i].second) {
      last = v[i].second;
    } else {
      last = v[i].first;
    }
  }
  cout << last << endl;
  return 0;
}
