#include <bits/stdc++.h>
const int nax = 5000 + 5;
using namespace std;
pair<int, int> arr[nax];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    arr[i] = {x, y};
  }
  sort(arr, arr + n);
  int day = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i].second < day) {
      day = arr[i].first;
    } else {
      day = arr[i].second;
    }
  }
  cout << day << "\n";
  return 0;
}
