#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5, mod = 1e9 + 7;
int n, m, org[N];
vector<pair<int, int> > edges;
vector<int> g[N];
bool vis[N];
int curEdges;
vector<int> v;
void dfs(int node) {
  v.push_back(node);
  for (auto child : g[node]) {
    curEdges++;
    if (vis[child]) continue;
    vis[child] = 1;
    dfs(child);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    edges.push_back({x, y});
    mp[x];
    mp[y];
  }
  for (auto &it : mp) it.second = ++m, org[m] = it.first;
  for (auto &it : edges)
    it.first = mp[it.first], it.second = mp[it.second],
    g[it.first].push_back(it.second), g[it.second].push_back(it.first);
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    if (vis[i]) continue;
    vis[i] = 1;
    v.clear();
    curEdges = 0;
    dfs(i);
    curEdges /= 2;
    if (curEdges > v.size()) return cout << -1, 0;
    sort(v.begin(), v.end());
    if (curEdges < v.size()) {
      v.pop_back();
    }
    if (v.size()) ans = max(ans, v.back());
  }
  cout << org[ans];
}
