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