#include <bits/stdc++.h>
const int N = 2000100;
int mt[N], a[N], b[N];
bool used[N];
std::vector<int> g[N];
bool kuhn(int v) {
  if (used[v]) {
    return false;
  }
  used[v] = true;
  for (auto to : g[v]) {
    if (used[to]) {
      continue;
    }
    if (mt[to] == -1 || kuhn(mt[to])) {
      mt[to] = v;
      return true;
    }
  }
  return false;
}
int main(void) {
  int n;
  scanf("%d", &n);
  std::vector<int> trans;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    --a[i];
    --b[i];
    trans.push_back(a[i]);
    trans.push_back(b[i]);
  }
  memset(mt, -1, sizeof(mt));
  std::sort(trans.begin(), trans.end());
  for (int i = 0; i < n; ++i) {
    int first =
        std::lower_bound(trans.begin(), trans.end(), a[i]) - trans.begin();
    int second =
        std::lower_bound(trans.begin(), trans.end(), b[i]) - trans.begin();
    g[first].push_back(i);
    g[second].push_back(i);
  }
  bool ansFl = false;
  for (int i = 0; i < std::min(N, trans.back() + 10); ++i) {
    memset(used, false, sizeof(used));
    kuhn(i);
    bool fl = true;
    for (int j = 0; j < n; ++j) {
      if (mt[j] == -1) {
        fl = false;
        break;
      }
    }
    if (fl) {
      ansFl = true;
      break;
    }
  }
  if (!ansFl) {
    printf("-1\n");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = std::max(ans, trans[mt[i]]);
  }
  printf("%d\n", ans + 1);
  return 0;
}
