#include <bits/stdc++.h>
using namespace std;
map<string, long long> m;
vector<pair<long long, long long> > v;
vector<pair<long long, long long> >::iterator it;
bool comp(const pair<long long, long long> &i,
          const pair<long long, long long> &j) {
  if (i.first == j.first) {
    return i.second < j.second;
  }
  return i.first < j.first;
}
int main() {
  long long t, i, n, j, x, y, res, k, cur = -1;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back({x, y});
  }
  sort(v.begin(), v.end(), comp);
  for (it = v.begin(); it != v.end(); it++) {
    if (cur <= it->second)
      cur = it->second;
    else
      cur = it->first;
  }
  cout << cur;
}
