#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int t;
  cin >> t;
  vector<pair<long long int, long long int>> a;
  long long int x, y;
  while (t--) {
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  sort(a.begin(), a.end());
  x = -1;
  long long int p, q;
  for (long long int i = 0; i < a.size(); i++) {
    if (a[i].first < a[i].second) {
      if (x <= a[i].first)
        x = a[i].first;
      else
        x = a[i].second;
    } else {
      if (x <= a[i].second)
        x = a[i].second;
      else
        x = a[i].first;
    }
  }
  cout << x;
  return 0;
}
