#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a, b;
  cin >> n;
  vector<pair<int, int> > arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    arr.emplace_back(a, b);
  }
  sort(arr.begin(), arr.end());
  int day = 0;
  for (auto p : arr) {
    if (p.second < day) {
      day = p.first;
    } else {
      day = p.second;
    }
  }
  cout << day;
}
