#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x, y;
  vector<pair<int, int> > v;
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end());
  int ans = v[0].second;
  for (int i = 1; i < t; i++) {
    if (v[i].second >= ans)
      ans = v[i].second;
    else
      ans = v[i].first;
  }
  cout << ans << "\n";
  return 0;
}
