#include <bits/stdc++.h>
using IntegerT = unsigned long long;
using ElemT = std::pair<IntegerT, IntegerT>;
namespace std {
template <class T1, class T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
  return is >> p.first >> p.second;
}
}  // namespace std
int main() {
  unsigned n{};
  std::cin >> n;
  std::vector<ElemT> dates(n);
  std::copy(std::istream_iterator<ElemT>{std::cin},
            std::istream_iterator<ElemT>{}, std::begin(dates));
  std::sort(std::begin(dates), std::end(dates));
  auto lastDate = std::accumulate(
      std::begin(dates), std::end(dates), IntegerT{},
      [](const IntegerT currentDate, const ElemT& examDates) {
        return ((currentDate <= examDates.second) ? examDates.second
                                                  : examDates.first);
      });
  std::cout << lastDate;
}
