#include <bits/stdc++.h>
using namespace std;
const int M = 1e7 + 5, N = 1e6 + 5, INF = 1e9;
vector<pair<int, int>> v[N];
int cp[M], fl[M], d[N], pt[N], days[N][2], srt[M];
int z = 0, s, t, mx, n;
bool bfs() {
  memset(d, -1, sizeof(d));
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (auto p : v[node]) {
      int to = p.first, num = p.second;
      if (node < n && to > mx) continue;
      if (d[to] == -1 && cp[num] > fl[num]) {
        d[to] = d[node] + 1;
        q.push(to);
      }
    }
  }
  return d[t] != -1;
}
int dfs(int node, int flow) {
  if (!flow || node == t) return flow;
  for (int &i = pt[node]; i < v[node].size(); i++) {
    int to = v[node][i].first, num = v[node][i].second;
    if (node < n && to > mx) continue;
    if (d[to] == d[node] + 1 && cp[num] > fl[num]) {
      int ret = dfs(to, min(flow, cp[num] - fl[num]));
      if (ret) {
        fl[num] += ret;
        fl[num ^ 1] -= ret;
        return ret;
      }
    }
  }
  return 0;
}
int maxFlow() {
  memset(fl, 0, sizeof(fl));
  int flow = 0;
  while (bfs()) {
    memset(pt, 0, sizeof(pt));
    int ret;
    while ((ret = dfs(s, INF))) {
      flow += ret;
    }
  }
  return flow;
}
int addE(int a, int b, int c, int d) {
  cp[z] = c;
  v[a].push_back({b, z++});
  cp[z] = d;
  v[b].push_back({a, z++});
  return z - 2;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    days[i][0] = a;
    days[i][0] = b;
    srt[i * 2] = a;
    srt[i * 2 + 1] = b;
  }
  sort(srt, srt + n + n);
  int ct = unique(srt, srt + n + n) - srt;
  s = N - 1, t = N - 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      addE(i, n + lower_bound(srt, srt + ct, days[i][j]) - srt, 1, 0);
    }
    addE(s, i, 1, 0);
  }
  for (int i = 0; i < ct; i++) {
    addE(i + n, t, 1, 0);
  }
  int l = -1, r = ct;
  while (r - l > 1) {
    int p = (r + l) >> 1;
    mx = p + n;
    int flow = maxFlow();
    if (flow == n) {
      r = p;
    } else {
      l = p;
    }
  }
  printf("%d\n", r == ct ? -1 : srt[r]);
  return 0;
}
