#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
int main(int argc, char const *argv[]) {
  int n;
  std::vector<pair<int, int> > exam;
  cin >> n;
  for (int i = 0; i < n; i++) {
    pair<int, int> p;
    int temp1, temp2;
    cin >> temp1 >> temp2;
    p.first = temp1;
    p.second = temp2;
    exam.push_back(p);
  }
  sort(exam.begin(), exam.end(), comp);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ans <= exam[i].second) {
      ans = exam[i].second;
    } else {
      ans = exam[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}
