#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
const int Maxn = 2000005;
int n;
int a[Maxn], b[Maxn];
vector<int> un;
bool tk[Maxn][2];
pair<int, int> to[Maxn];
bool is[Maxn];
pair<int, int> Get(const pair<int, int> &p) {
  pair<int, int> res;
  res.first = p.second;
  res.second = a[p.second] == p.first ? 0 : 1;
  return res;
}
bool Remove(int v, pair<int, int> from) {
  if (!is[v]) {
    is[v] = true;
    to[v] = from;
    return true;
  }
  if (to[v].first == -1) return false;
  pair<int, int> got = Get(to[v]);
  if (tk[got.first][got.second]) return false;
  tk[got.first][got.second] = true;
  if (Remove(to[v].first, pair<int, int>(v, to[v].second))) {
    to[v] = from;
    return true;
  }
  return false;
}
bool Okay(int x) {
  fill(is, is + int(un.size()), false);
  fill((bool *)tk, (bool *)tk + Maxn * 2, false);
  for (int i = 0; i < n; i++) {
    if (a[i] <= x && !is[a[i]]) {
      is[a[i]] = true;
      to[a[i]] = pair<int, int>((b[i] <= x ? b[i] : -1), i);
      continue;
    }
    if (b[i] <= x && !is[b[i]]) {
      is[b[i]] = true;
      to[b[i]] = pair<int, int>(a[i], i);
      continue;
    }
    if (b[i] <= x)
      if (Remove(b[i], pair<int, int>(a[i], i)))
        ;
      else if (Remove(a[i], pair<int, int>(b[i], i)))
        ;
      else
        return false;
    else if (a[i] <= x)
      if (Remove(a[i], pair<int, int>(-1, i)))
        ;
      else
        return false;
    else
      return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    un.push_back(a[i]);
    un.push_back(b[i]);
  }
  sort(un.begin(), un.end());
  un.erase(unique(un.begin(), un.end()), un.end());
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound(un.begin(), un.end(), a[i]) - un.begin();
    b[i] = lower_bound(un.begin(), un.end(), b[i]) - un.begin();
  }
  int lef = 0, rig = int(un.size()) - 1;
  while (lef <= rig) {
    int mid = lef + rig >> 1;
    if (Okay(mid))
      rig = mid - 1;
    else
      lef = mid + 1;
  }
  rig++;
  if (rig >= un.size())
    printf("-1\n");
  else
    printf("%d\n", un[rig]);
  return 0;
}
