#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
long long n;
vector<pair<long long, long long> > v;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  long long resp = 0;
  for (int i = 0; i < n; ++i) {
    if (v[i].second >= resp)
      resp = v[i].second;
    else
      resp = v[i].first;
  }
  cout << resp << endl;
  return 0;
}
