#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int ans;
int n, m;
int tmp[4];
int a[maxn][2];
int mark[maxn];
vector<int> cmp;
map<int, int> compress;
vector<int> adj[maxn];
void in();
void solve();
void make();
int fix(int);
pair<int, int> getsum(int);
pair<int, int> domax(int);
pair<int, int> get(pair<int, int>, pair<int, int>);
void out();
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int t = 1;
  for (int i = 0; i < t; i++) {
    in();
    solve();
    out();
  }
}
void in() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1];
    cmp.push_back(a[i][0]);
    cmp.push_back(a[i][1]);
  }
  sort(cmp.begin(), cmp.end());
  cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());
  m = cmp.size();
  for (int i = 0; i < m; i++) compress[cmp[i]] = i;
  for (int i = 0; i < n; i++) {
    a[i][0] = compress[a[i][0]];
    a[i][1] = compress[a[i][1]];
  }
}
void solve() {
  make();
  ans = 0;
  for (int i = 0; i < m; i++) {
    if (!mark[i]) {
      int z = fix(i);
      ans = max(ans, z);
      if (z == -1) {
        ans = -1;
        return;
      }
    }
  }
}
int fix(int u) {
  auto x = getsum(u);
  auto oof = domax(u);
  if (n == 1000000)
    cout << adj[u].size() << ' ' << x.first << ' ' << x.second << endl;
  if (x.first / 2 > x.second) return -1;
  if (x.first / 2 == x.second) return oof.first;
  return oof.second;
}
pair<int, int> domax(int u) {
  mark[u] = 2;
  pair<int, int> ret = {u, 0};
  for (auto v : adj[u])
    if (mark[v] == 1) ret = get(ret, domax(v));
  return ret;
}
pair<int, int> get(pair<int, int> a, pair<int, int> b) {
  tmp[0] = a.first;
  tmp[1] = a.second;
  tmp[2] = b.first;
  tmp[3] = b.second;
  sort(tmp, tmp + 4);
  return {tmp[3], tmp[2]};
}
pair<int, int> getsum(int u) {
  mark[u] = 1;
  int ret = adj[u].size();
  int rot = 1;
  for (auto v : adj[u]) {
    if (!mark[v]) {
      auto x = getsum(v);
      ret += x.first;
      rot += x.second;
    }
  }
  return {ret, rot};
}
void make() {
  for (int i = 0; i < n; i++) {
    adj[a[i][0]].push_back(a[i][1]);
    adj[a[i][1]].push_back(a[i][0]);
  }
}
void out() {
  if (ans == -1)
    cout << -1;
  else
    cout << cmp[ans];
}
