#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], b[N], n;
vector<int> val;
bool was[N];
int root[N], edge[N];
int res;
int get_root(int u) {
  while (root[u] > 0) {
    u = root[u];
  }
  return u;
}
void union_set(int r1, int r2) {
  if (root[r1] > root[r2]) {
    root[r2] += root[r1];
    edge[r2] += edge[r1] + 1;
    root[r1] = r2;
  } else {
    root[r1] += root[r2];
    edge[r1] += edge[r2] + 1;
    root[r2] = r1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    val.push_back(a[i]);
    val.push_back(b[i]);
  }
  sort(val.begin(), val.end());
  val.erase(unique(val.begin(), val.end()), val.end());
  for (int i = 0; i < val.size(); i++) {
    root[i] = -1;
    edge[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    int u, v;
    u = lower_bound(val.begin(), val.end(), a[i]) - val.begin();
    v = lower_bound(val.begin(), val.end(), b[i]) - val.begin();
    int r1 = get_root(u), r2 = get_root(v);
    if (r1 != r2) {
      union_set(r1, r2);
    } else {
      edge[r1]++;
    }
  }
  for (int i = val.size() - 1; i >= 0; i--) {
    int r = get_root(i);
    if (edge[r] > -root[r]) {
      cout << -1;
      return 0;
    }
  }
  for (int i = val.size() - 1; i >= 0; i--) {
    int r = get_root(i);
    if (edge[r] == -root[r]) {
      cout << val[i];
      return 0;
    } else {
      if (was[r]) {
        cout << val[i];
        return 0;
      }
      was[r] = true;
    }
  }
}
