#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > info;
int main() {
  int n;
  scanf("%d", &n);
  info.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> info[i].first >> info[i].second;
  }
  sort((info).begin(), (info).end());
  int prev = min(info[0].first, info[0].second);
  for (int i = 1; i < n; i++) {
    if (info[i].second >= prev)
      prev = info[i].second;
    else
      prev = info[i].first;
  }
  printf("%d", prev);
}
