#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
template <typename T>
inline istream& operator>>(istream& in, pair<T, T>& v) {
  in >> v.first >> v.second;
  return in;
}
template <typename T>
inline ostream& operator<<(ostream& out, pair<T, T> v) {
  out << v.first << " " << v.second;
  return out;
}
template <typename T>
inline istream& operator>>(istream& in, vector<T>& v) {
  for (int i = 0; i < (int)((v).size()); i++) in >> v[i];
  return in;
}
template <typename T>
inline ostream& operator<<(ostream& out, vector<T>& v) {
  for (int i = 0; i < (int)((v).size()); i++) out << v[i] << " ";
  return out;
}
template <typename T>
inline istream& operator>>(istream& in, pair<vector<T>*, vector<T>*> v) {
  for (int i = 0; i < (int)((*v.first).size()); i++)
    in >> (*v.first)[i] >> (*v.second)[i];
  return in;
}
const int inf = numeric_limits<int>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(-1);
struct graph {
  int n;
  vector<vector<int> > adj;
  graph() {}
  graph(int n_) {
    n = n_;
    adj.resize(n);
  }
  inline void insert(int v, int u) {
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
};
int n, mark = 0;
vector<int> a, b, cd;
graph g;
vector<int> used, mt;
inline void reduce() {
  vector<int> v;
  for (int i = 0; i < n; i++) {
    v.push_back(a[i]);
    v.push_back(b[i]);
  }
  unique((v).begin(), (v).end());
  sort((v).begin(), (v).end());
  for (int p : v) {
    cd.push_back(p);
  }
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound((v).begin(), (v).end(), a[i]) - v.begin();
    b[i] = lower_bound((v).begin(), (v).end(), b[i]) - v.begin();
  }
}
inline void build() {
  g = graph(4 * n);
  for (int i = 0; i < n; i++) {
    g.insert(a[i], (int)((cd).size()) + i);
    g.insert(b[i], (int)((cd).size()) + i);
  }
}
inline bool kuhn(int v) {
  if (used[v] == mark) {
    return 0;
  }
  used[v] = mark;
  for (int u : g.adj[v]) {
    if (mt[u] == -1) {
      mt[u] = v, mt[v] = u;
      return 1;
    }
  }
  for (int u : g.adj[v]) {
    if (kuhn(mt[u])) {
      mt[u] = v, mt[v] = u;
      return 1;
    }
  }
  return 0;
}
inline void solve() {
  build();
  ++mark;
  used.assign(g.n, 0), mt.assign(g.n, -1);
  int ans = 0;
  int last = -1;
  for (int v = 0; v < (int)((cd).size()); v++) {
    if (ans >= n) {
      break;
    }
    for (int u : g.adj[v]) {
      if (mt[u] == -1) {
        continue;
      }
      mt[u] = v;
      mt[v] = u;
      ++ans;
      if (ans >= n) {
        last = v;
      }
      break;
    }
  }
  for (int i = 0; i < (int)((cd).size()); i++) {
    if (ans >= n) {
      break;
    }
    if (kuhn(i)) {
      ++mark;
      ++ans;
      if (ans == n) {
        last = cd[i];
        break;
      }
    }
  }
  cout << last << "\n";
}
inline void read() {
  cin >> n;
  a.resize(n), b.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  reduce();
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read();
  solve();
  return 0;
}
