#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> vec;
int main() {
  int n;
  cin >> n;
  for (int tt = 0; tt < n; tt++) {
    int x, y;
    cin >> x >> y;
    vec.push_back({x, y});
  }
  sort(vec.begin(), vec.end());
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (ans <= vec[i].second)
      ans = vec[i].second;
    else
      ans = vec[i].first;
  }
  cout << ans << endl;
}
