#include <bits/stdc++.h>
using namespace std;
struct rec {
  int a, b;
} E[5005];
int n;
bool cmp(const rec &i, const rec &j) {
  return i.a == j.a ? i.b < j.b : i.a < j.a;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &E[i].a, &E[i].b);
  sort(E + 1, E + 1 + n, cmp);
  int now = 0;
  for (int i = 1; i <= n; i++)
    if (now > E[i].b)
      now = E[i].a;
    else
      now = E[i].b;
  printf("%d\n", now);
}
