#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<int, int> > v;
  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());
  int l = 0;
  for (int i = 0; i < n; i++) {
    if (l <= v[i].second) {
      l = v[i].second;
    } else {
      l = v[i].first;
    }
  }
  cout << l;
}
