#include <bits/stdc++.h>
using namespace std;
pair<int, int> pr[6000];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &pr[i].first, &pr[i].second);
  sort(pr + 1, pr + n + 1);
  int last = pr[1].second;
  for (int i = 2; i <= n; i++) {
    if (pr[i].second >= last)
      last = pr[i].second;
    else
      last = pr[i].first;
  }
  printf("%d\n", last);
  return 0;
}
