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