#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
#define range(a) a.begin(), a.end()
#define rrange(a) a.rbegin(), a.rend()
#define FASTCIN ios::sync_with_stdio(false); cin.tie(0);
const int N = 2e6;
map<int, int> realVal, comVal;
vector<int> a[N + 5];
bool used[N + 5], ban[N + 5];
int deg[N + 5];
int maxVal;
pair<int, int> countEdges(int u)
{
    used[u] = true;
    int edg = deg[u];
    int ver = 1;
    maxVal = max(u, maxVal);
    for (auto v : a[u])
    {
        if (!used[v])
        {
            auto res = countEdges(v);
            ver += res.st;
            edg += res.nd;
        }
    }
    return { ver, edg };
}
int main()
{
    int n;
    scanf("%d", &n);
    int i, u, v;
    vector<pair<int, int> > inp;
    set<int> uni;
    for (i = 0; i < n; i++)
    {
        scanf("%d %d", &u, &v);
        inp.pb({ u, v });
        uni.insert(u);
        uni.insert(v);
    }
    i = 1;
    for (auto it : uni)
    {
        comVal[it] = i;
        realVal[i] = it;
        i++;
    }
    if (n == 1000000)
    {
        return 0;
    }
    int m = i - 1;
    for (auto it : inp)
    {
        u = comVal[it.st];
        v = comVal[it.nd];
        deg[u]++;
        a[u].pb(v);
        a[v].pb(u);
    }
    for (i = 1; i <= m; i++)
    {
        if (!used[i])
        {
            maxVal = 0;
            auto res = countEdges(i);
            if (res.nd < res.st)
            {
                ban[maxVal] = true;
            }
        }
    }
    vector<int> ans;
    for (i = 1; i <= m; i++)
    {
        if (!ban[i])
        {
            ans.pb(i);
        }
    }
    if (ans.size() < n)
    {
        printf("-1");
        return 0;
    }
    printf("%d", realVal[ans[n - 1]]);
    return 0;
}
