#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  pair<int, int> A[5007];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second;
  sort(A, A + n);
  int day = min(A[0].first, A[0].second);
  for (int i = 1; i < n; i++) {
    if (A[i].second < day)
      day = max(A[i].first, day);
    else
      day = max(A[i].second, day);
  }
  cout << day << endl;
  return 0;
}
