#include <bits/stdc++.h>
using namespace std;
int dp[5007][2];
struct node {
  int a, b;
} k[5007];
int cmp(node ka, node kb) {
  if (ka.a == kb.a) return ka.b < kb.b;
  return ka.a < kb.a;
}
int main() {
  int n, i;
  while (scanf("%d", &n) != EOF) {
    memset(dp, 0, sizeof(dp));
    for (i = 1; i <= n; i++) scanf("%d%d", &k[i].a, &k[i].b);
    sort(k + 1, k + n + 1, cmp);
    for (i = 1; i <= n; i++) {
      if (k[i].b >= min(dp[i - 1][0], dp[i - 1][1])) {
        dp[i][0] = k[i].b;
        dp[i][1] = k[i].a;
      } else {
        dp[i][0] = 1000000007;
        dp[i][1] = k[i].a;
      }
    }
    cout << min(dp[n][0], dp[n][1]) << endl;
  }
  return 0;
}
