#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, last = 0;
  vector<pair<int, int> > v;
  scanf("%d", &n);
  while (n--) {
    scanf("%d %d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    int mn = min(v[i].first, v[i].second);
    if (mn >= last)
      last = mn;
    else
      last = v[i].first;
  }
  printf("%d\n", last);
  return 0;
}
