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