#include <bits/stdc++.h>
using namespace std;
inline void opting() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
}
long long inp() {
  long long x;
  cin >> x;
  return x;
}
void make_unique(vector<int> &vec, bool sorted = false) {
  if (!sorted) sort((vec).begin(), (vec).end());
  vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());
}
const long long SQRT = 450, lg = 18 + 2, inlim = 2147483647;
const long long maxn = 2e6 + 10, CL = 40, delta = 1e9 + 7, inf = 1e9 + 420,
                p2 = 2, mod = 1e9 + 9;
int mini, n;
vector<int> days;
vector<pair<int, int> > adj_tmp;
bitset<maxn> mark;
vector<int> adj[maxn];
inline int maped_val(int x) {
  return lower_bound((days).begin(), (days).end(), x) - days.begin();
}
void main_edges() {
  for (auto p : adj_tmp) {
    p.first = maped_val(p.first);
    p.second = maped_val(p.second);
    adj[p.first].push_back(p.second);
    adj[p.second].push_back(p.first);
    mini = max(mini, min(p.first, p.second));
  }
}
void add_edge(int u, int v) {
  adj_tmp.push_back(make_pair(u, v));
  days.push_back(u);
  days.push_back(v);
}
pair<int, int> DFS(int v, int k, int par) {
  mark[v] = true;
  int N, E;
  N = 1;
  E = 0;
  for (auto u : adj[v])
    if (!mark[u] and u <= k) {
      pair<int, int> tmp = DFS(u, k, v);
      N += tmp.first;
      E += tmp.second;
    } else
      E += (!mark[u] or (u < v) or u == par);
  return make_pair(N, E);
}
bool check(int key) {
  mark.reset();
  for (int d = 0; d <= key; d++)
    if (!mark[d]) {
      pair<int, int> P = DFS(d, key, -1);
      if (P.first < P.second) return false;
    }
  return true;
}
int solve() {
  int st = mini - 1;
  int en = days.size();
  if (!check(en)) return -1;
  while (en - st > 1) {
    int mid = (st + en) >> 1;
    if (check(mid))
      en = mid;
    else
      st = mid;
  }
  return days[st + 1];
}
void input() {
  int m = inp();
  for (int i = 0; i < m; i++) add_edge(inp(), inp());
  make_unique(days);
  main_edges();
}
int main() {
  opting();
  input();
  cout << solve();
}
