#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  vector<pair<long long, long long> > v;
  while (n--) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  int x = v[0].second;
  for (int i = 1; i < v.size(); i++) {
    if (v[i].second >= x && v[i].second < v[i].first) {
      x = v[i].second;
    } else
      x = v[i].first;
  }
  cout << x << endl;
}
