#include <bits/stdc++.h>
using namespace std;
int n;
int ans;
int now;
typedef struct {
  int a;
  int b;
} PP;
PP p[5005];
bool cmp(PP x, PP y) {
  if (x.a == y.a) {
    return x.b < y.b;
  } else {
    return x.a < y.a;
  }
}
void ini() {
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].a, &p[i].b);
  }
}
void solve() {
  sort(p + 1, p + 1 + n, cmp);
  int i;
  now = p[1].b;
  for (i = 2; i <= n; i++) {
    if (p[i].b >= now) {
      now = p[i].b;
    } else {
      now = p[i].a;
    }
  }
}
void out() { printf("%d\n", now); }
int main() {
  while (scanf("%d", &n) != EOF) {
    ini();
    solve();
    out();
  }
  return 0;
}
