#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
int n, m, d[5005];
node a[5005];
bool cmp(const node &x, const node &y) {
  return x.x == y.x ? x.y < y.y : x.x < y.x;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y);
  sort(a + 1, a + 1 + n, cmp);
  memset(d, 0, sizeof(d));
  int ans = min(a[1].x, a[1].y);
  for (int i = 2; i <= n; i++)
    if (ans > a[i].y)
      ans = a[i].x;
    else
      ans = a[i].y;
  printf("%d\n", ans);
  return 0;
}
