#include <bits/stdc++.h>
using namespace std;
int n, i, m;
int main() {
  cin >> n;
  pair<int, int> p[n];
  for (i = 0; i < n; ++i) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + n);
  for (i = 0; i < n; ++i) {
    if (p[i].second >= m)
      m = p[i].second;
    else
      m = p[i].first;
  }
  cout << m << '\n';
}
