#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<long long, long long>& a,
          const pair<long long, long long>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > day(n);
  vector<long long> state(n);
  pair<long long, long long> temp;
  for (int i = 0; i < n; i++) {
    cin >> temp.first >> temp.second;
    day[i] = temp;
  }
  long long today;
  sort(day.begin(), day.end(), comp);
  today = day[0].second;
  state[0] = today;
  for (int i = 1; i < n; i++) {
    if (day[i].second >= today) {
      today = day[i].second;
      state[i] = today;
    } else {
      today = day[i].first;
      state[i] = today;
    }
  }
  for (int i = 0; i < n; i++) {
    if (state[i] > today) today = state[i];
  }
  cout << today << endl;
  return 0;
}
