#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int> > v(n);
  for (int i = 0; i < n; ++i) scanf("%d%d", &v[i].first, &v[i].second);
  sort(v.begin(), v.end());
  int thisDay = 0;
  for (auto x : v) {
    if (x.second < thisDay)
      thisDay = x.first;
    else
      thisDay = x.second;
  }
  printf("%d\n", thisDay);
}
