#include <bits/stdc++.h>
using namespace std;
struct node {
  int f, s;
} p[5050];
bool cmp(node a, node b) {
  if (a.f < b.f) return true;
  if (a.f == b.f && a.s < b.s) return true;
  return false;
}
int n;
int main() {
  scanf("%d", &n);
  int ta, tb;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &ta, &tb);
    p[i].f = ta;
    p[i].s = tb;
  }
  sort(p + 1, p + 1 + n, cmp);
  int t = p[1].f;
  for (int i = 2; i <= n; i++) {
    if (p[i].s >= t)
      t = p[i].s;
    else if (p[i].f >= t)
      t = p[i].f;
    else {
      t = 2147483647;
      break;
    }
  }
  int k = p[1].s;
  for (int i = 2; i <= n; i++) {
    if (p[i].s >= k)
      k = p[i].s;
    else if (p[i].f >= k)
      k = p[i].f;
    else {
      k = 2147483647;
      break;
    }
  }
  printf("%d\n", min(t, k));
}
