#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj(2000000);
vector<int> c;
int parent[2000000], v[2000000], e[2000000];
pair<int, int> a[2000000];
bool visited[2000000];
int Find(int i) { return (i == parent[i]) ? i : parent[i] = Find(parent[i]); }
void Union(int i, int j) {
  if (visited[i] == 1 || visited[j] == 1) {
    return;
  }
  i = Find(i), j = Find(j);
  if (i == j) {
    if (e[i] < v[i]) {
      ++e[i];
    }
  } else {
    if (i > j) {
      swap(i, j);
    }
    parent[j] = i;
    v[i] += v[j];
    e[i] += e[j];
    e[i] += (e[i] < v[i]);
  }
}
bool Check(int n, int t) {
  for (int i = 0; i <= t; ++i) {
    v[i] = 1;
    e[i] = 0;
    visited[i] = 0;
    parent[i] = i;
  }
  queue<int> Q;
  for (int i = t + 1; i < c.size(); ++i) {
    Q.push(i);
  }
  while (!Q.empty()) {
    int i = Q.front();
    Q.pop();
    for (auto j : adj[i]) {
      if (j > t) {
        continue;
      }
      if (visited[j] == 0) {
        e[j] = 1;
        visited[j] = 1;
        Q.push(j);
      }
    }
  }
  for (int i = 0; i <= t; ++i) {
    for (auto j : adj[i]) {
      Union(i, j);
    }
  }
  for (int i = 0; i <= t; ++i) {
    n -= e[i];
  }
  return (n == 0);
}
int BinarySearch(int n) {
  int x = 0, y = c.size() - 1, z = c.size();
  while (x <= y) {
    int mid = x + (y - x) / 2;
    if (Check(n, mid)) {
      z = mid, y = mid - 1;
    } else {
      x = mid + 1;
    }
  }
  return z == c.size() ? -1 : c[z];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int x = 0; x < n; ++x) {
    int i, j;
    scanf("%d%d", &i, &j);
    c.push_back(i);
    c.push_back(j);
    a[x] = make_pair(i, j);
  }
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
  for (int x = 0; x < n; ++x) {
    int i, j;
    tie(i, j) = a[x];
    i = lower_bound(c.begin(), c.end(), i) - c.begin();
    j = lower_bound(c.begin(), c.end(), j) - c.begin();
    adj[i].push_back(j);
    adj[j].push_back(i);
  }
  printf("%d\n", BinarySearch(n));
  return 0;
}
