#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > g;
map<int, bool> used;
map<int, int> p;
bool kuhn(int v) {
  if (used[v]) {
    return 0;
  }
  used[v] = 1;
  for (auto to : g[v]) {
    if (p[to] == -1 || kuhn(p[to])) {
      p[to] = v;
      return 1;
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> days;
  map<int, bool> was1;
  map<pair<int, int>, bool> was2;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    if (!was1[x]) {
      days.push_back(x);
      was1[x] = 1;
    }
    if (!was1[y]) {
      days.push_back(y);
      was1[y] = 1;
    }
    if (!was2[make_pair(x, x)]) {
      g[x].push_back(x);
      was2[make_pair(x, x)] = 1;
    }
    if (!was2[make_pair(x, y)]) {
      g[x].push_back(y);
      was2[make_pair(x, y)] = 1;
    }
    if (!was2[make_pair(y, x)]) {
      g[y].push_back(x);
      was2[make_pair(y, x)] = 1;
    }
    if (!was2[make_pair(y, y)]) {
      g[y].push_back(y);
      was2[make_pair(y, y)] = 1;
    }
    p[x] = -1;
    p[y] = -1;
  }
  sort(days.begin(), days.end());
  long long cnt = 0;
  for (auto it : days) {
    used.clear();
    if (kuhn(it)) {
      ++cnt;
      if (cnt == n) {
        cout << it;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
