#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
unordered_map<int, int> Mp;
const int MAXN = 1111111;
int a[MAXN], b[MAXN], ord[MAXN];
int n, m, ans;
inline bool cmp(int x, int y) {
  return b[x] != b[y] ? b[x] > b[y] : a[x] > a[y];
}
inline int check(int x) {
  Mp.clear();
  for (int it = 1; it <= n; ++it) {
    int i = ord[it];
    if (a[i] > x) return 0;
    if (b[i] <= x && Mp.find(b[i]) == Mp.end()) {
      Mp[b[i]] = 1;
    } else if (Mp.find(a[i]) == Mp.end()) {
      Mp[a[i]] = 1;
    } else {
      return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    ord[i] = i;
    scanf("%d%d", &a[i], &b[i]);
  }
  sort(ord + 1, ord + 1 + n);
  int L = 0, R = 1e9;
  ans = -1;
  while (L <= R) {
    int mid = (L + R) >> 1;
    if (check(mid)) {
      ans = mid;
      R = mid - 1;
    } else {
      L = mid + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
