#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
vector<pair<int, int> > edges;
vector<int> adj[2000005];
vector<bool> visited;
bool isgood(int days) {
  int nodes = 0;
  for (auto& i : edges) {
    if (min(i.first, i.second) > days) return false;
    nodes = max(nodes, max(i.first, i.second));
  }
  fill((visited).begin(), (visited).end(), 0);
  for (int i = 1; i < nodes + 1; i++) {
    if (visited[i]) continue;
    queue<int> q;
    int e = 0;
    int n = 0;
    int b = 0;
    q.push(i);
    while (!q.empty()) {
      auto cur = q.front();
      q.pop();
      if (visited[cur]) continue;
      visited[cur] = 1;
      n++;
      e += (int)adj[cur].size();
      if (cur > days) b++;
      for (auto j : adj[cur]) {
        q.push(j);
      }
    }
    e /= 2;
    if (e > n - b) return false;
  }
  return true;
}
void solve() {
  int n;
  cin >> n;
  vector<int> s;
  edges.resize(n);
  for (int i = 1; i < n + 1; i++) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    s.push_back(temp1);
    s.push_back(temp2);
    edges[i - 1] = make_pair(temp1, temp2);
  }
  sort((s).begin(), (s).end());
  s.resize(unique((s).begin(), (s).end()) - s.begin());
  for (auto& i : edges) {
    i.first = lower_bound((s).begin(), (s).end(), i.first) - s.begin() + 1;
    i.second = lower_bound((s).begin(), (s).end(), i.second) - s.begin() + 1;
    ;
    adj[i.first].emplace_back(i.second);
    adj[i.second].emplace_back(i.first);
  }
  visited.resize((int)s.size() + 1);
  int mina = 0;
  int maxa = (int)s.size() + 1;
  while (maxa - mina > 1) {
    int mid = mina + (maxa - mina) / 2;
    if (isgood(mid))
      maxa = mid;
    else
      mina = mid;
  }
  if (maxa == (int)s.size() + 1)
    cout << -1 << '\n';
  else {
    cout << s[maxa - 1] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
