#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  sort(begin(a), end(a));
  int prev = a[0].second;
  for (int i = 0; i < n; i++) {
    if (a[i].second < prev) {
      prev = a[i].first;
    } else {
      prev = a[i].second;
    }
  }
  cout << prev << endl;
  return 0;
}
