#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[5010];
int dp[5010][2];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) scanf("%d%d", &p[i].first, &p[i].second);
    sort(p, p + n);
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1, dp[0][1] = 1;
    for (int i = 1; i < n; i++) {
      if (dp[i - 1][0]) {
        if (p[i].first >= p[i - 1].first) {
          dp[i][0] = 1;
        }
        if (p[i].second >= p[i - 1].first) {
          dp[i][1] = 1;
        }
      }
      if (dp[i - 1][1]) {
        if (p[i].first >= p[i - 1].second) {
          dp[i][0] = 1;
        }
        if (p[i].second >= p[i - 1].second) {
          dp[i][1] = 1;
        }
      }
    }
    int ans = 1000000000;
    if (dp[n - 1][1]) ans = min(ans, p[n - 1].second);
    if (dp[n - 1][0]) ans = min(ans, p[n - 1].first);
    printf("%d\n", ans);
  }
  return 0;
}
