#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e) {
  long long p = 1;
  while (e > 0) {
    if (e & 1) {
      p = (p * b) % 1000000007;
    }
    e = e >> 1;
    b = (b * b) % 1000000007;
  }
  return p;
}
pair<long long, long long> day[5001];
int main() {
  long long n, i, t, x = 0, l, r, m;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &l);
    scanf("%lld", &r);
    day[i].first = l;
    day[i].second = r;
  }
  sort(day, day + n);
  for (i = 0; i < n; i++) {
    if (day[i].second >= x)
      x = day[i].second;
    else
      x = day[i].first;
  }
  printf("%lld\n", x);
  return 0;
}
