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