#include <bits/stdc++.h>
using namespace std;
int N;
pair<int, int> D[5001];
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> D[i].first >> D[i].second;
  }
  sort(D + 1, D + N + 1);
  int DATE = 0;
  for (int i = 1; i <= N; i++) {
    if (DATE <= D[i].second)
      DATE = D[i].second;
    else
      DATE = D[i].first;
  }
  cout << DATE << endl;
  return 0;
}
