#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[5100];
int f[5100][2];
int n;
const int inf = 0x7fffffff;
inline int getmin(int x, int y) { return x < y ? x : y; }
void conduct() {
  int i;
  a[0].first = a[0].second = 0;
  for (i = 1; i <= n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a, a + n + 1);
  f[0][0] = f[0][1] = 0;
  for (i = 1; i <= n; ++i) {
    f[i][0] = a[i].first;
    if (a[i].second >= f[i - 1][0] || a[i].second >= f[i - 1][1])
      f[i][1] = a[i].second;
    else
      f[i][1] = inf;
  }
  printf("%d\n", getmin(f[n][0], f[n][1]));
}
int main() {
  while (scanf("%d", &n) != EOF) conduct();
  return 0;
}
