#include <bits/stdc++.h>
void debug(std::vector<std::pair<long long int, long long int> > x) {
  for (auto y : x) {
    std::cout << y.first << " " << y.second << "\n";
  }
}
int main() {
  long long int n, a, b, maks = -1;
  std::cin >> n;
  std::vector<std::pair<long long int, long long int> > v;
  while (n--) {
    std::cin >> a >> b;
    v.push_back({a, b});
  }
  std::sort(v.begin(), v.end());
  for (size_t i = 0; i < v.size(); i++) {
    if (maks <= v[i].second) {
      maks = v[i].second;
    } else {
      maks = v[i].first;
    }
  }
  std::cout << maks << "\n";
  return 0;
}
