#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > dates;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    dates.emplace_back(a, b);
  }
  sort(dates.begin(), dates.end());
  int min_date = 0;
  for (pair<int, int> &date : dates) {
    if (date.second < min_date) {
      date.second = date.first;
    }
    min_date = min(date.first, date.second);
  }
  cout << min_date;
  return 0;
}
