#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, x, y;
  cin >> n;
  long long int a[n], b[n];
  pair<long long int, long long int> p[n];
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    p[i] = make_pair(x, y);
  }
  sort(p, p + n, compare);
  int last = p[0].second;
  for (int i = 1; i < n; i++) {
    if (p[i].second >= last)
      last = p[i].second;
    else
      last = p[i].first;
  }
  cout << last << "\n";
}
