#include <bits/stdc++.h>
using namespace std;
std::pair<long long int, long long int> V[10005];
int main() {
  long long int n;
  scanf("%lld", &n);
  long long int x, y, m = -1;
  for (int i = 0; i <= n - 1; i++) {
    scanf("%lld %lld", &x, &y);
    V[i].first = x;
    V[i].second = y;
    m = max(y, m);
  }
  int temp;
  std::sort(V, V + n);
  long long int best = -1;
  for (int i = 0; i <= n - 1; i++) {
    if (best <= V[i].second)
      best = V[i].second;
    else
      best = V[i].first;
  }
  printf("%lld\n", best);
  return 0;
}
