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