#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
const int Maxn = 2000005;
int n;
int a[Maxn], b[Maxn];
pair<int, int> seq[Maxn];
vector<int> un;
bool tk[Maxn];
int to[Maxn];
bool is[Maxn];
bool Remove(int v, int from) {
  if (!is[v]) {
    is[v] = true;
    tk[v] = false;
    to[v] = from;
    return true;
  }
  if (tk[v]) return false;
  tk[v] = true;
  if (to[v] == -1) return false;
  if (Remove(to[v], v)) {
    to[v] = from;
    return true;
  }
  return false;
}
bool Okay(int x) {
  fill(is, is + int(un.size()), false);
  for (int i = 0; i < n; i++)
    if (seq[i].second <= x)
      if (Remove(seq[i].second, seq[i].first))
        tk[seq[i].second] = false;
      else if (Remove(seq[i].first, seq[i].second))
        tk[seq[i].first] = false;
      else
        return false;
    else if (seq[i].first <= x)
      if (Remove(seq[i].first, -1))
        tk[seq[i].first] = false;
      else
        return false;
    else
      return false;
  return true;
}
bool Less(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second != b.second) return a.second > b.second;
  return a.first > b.first;
}
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();
    seq[i] = pair<int, int>(a[i], b[i]);
  }
  sort(seq, seq + n, Less);
  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;
}
