#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> M;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    M.push_back({a, b});
  }
  int ans = -1;
  sort(M.begin(), M.end());
  for (auto i : M) {
    if (ans > i.second) {
      ans = i.first;
    } else {
      ans = i.second;
    }
  }
  cout << ans;
  return 0;
}
