#include <bits/stdc++.h>
template <typename T>
void MACRO_VAR_Scan(T& t) {
  std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
  std::cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
  t.resize(n);
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {
  first.resize(n);
  MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T>
void MACRO_VEC_ROW_Scan(int p, T& t) {
  std::cin >> t[p];
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {
  std::cin >> first[p];
  MACRO_VEC_ROW_Scan(p, rest...);
}
template <class T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
void CHECKTIME(std::function<void()> f) {
  auto start = std::chrono::system_clock::now();
  f();
  auto end = std::chrono::system_clock::now();
  auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))
                 .count();
  std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n";
}
template <class T>
std::vector<std::vector<T>> VV(int n, int m, T init = T()) {
  return std::vector<std::vector<T>>(n, std::vector<T>(m, init));
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;
constexpr int INFINT_LIM = (1LL << 31) - 1;
constexpr ll INFLL = 1LL << 60;
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
constexpr double EPS = 1e-10;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template <class T, size_t N>
void FILL(T (&a)[N], const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, size_t N, size_t M, class T>
void FILL(ARY (&a)[N][M], const T& val) {
  for (auto& b : a) FILL(b, val);
}
template <class T>
void FILL(std::vector<T>& a, const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, class T>
void FILL(std::vector<std::vector<ARY>>& a, const T& val) {
  for (auto& b : a) FILL(b, val);
}
class UnionFind {
 private:
  std::vector<int> data;

 public:
  UnionFind(int size_) : data(size_, -1) {}
  inline void init(int size_) {
    data.resize(size_);
    data.assign(size_, -1);
  }
  inline int find(int x) {
    if (data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  inline void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (data[x] > data[y])
      data[y] += data[x], data[x] = y;
    else
      data[x] += data[y], data[y] = x;
  }
  inline bool same(int x, int y) { return find(x) == find(y); }
  inline int size(int x) { return -data[find(x)]; }
};
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int n;
  MACRO_VAR_Scan(n);
  ;
  std::vector<int> a, b;
  MACRO_VEC_ROW_Init(n, a, b);
  for (int i = 0; i < n; ++i) {
    MACRO_VEC_ROW_Scan(i, a, b);
  };
  std::map<int, int> map;
  for (int i = 0; i < int(n); ++i) map[a[i]], map[b[i]];
  map[0];
  map[MOD];
  int sz = 0;
  for (auto& x : map) x.second = sz++;
  std::vector<int> inv(sz);
  for (auto& x : map) inv[x.second] = x.first;
  for (int i = 0; i < int(n); ++i) a[i] = map[a[i]];
  for (int i = 0; i < int(n); ++i) b[i] = map[b[i]];
  {
    std::vector<PAIR> v(n);
    for (int i = 0; i < int(n); ++i) v[i] = PAIR(a[i], b[i]);
    std::sort((v).begin(), (v).end());
    std::reverse((v).begin(), (v).end());
    for (int i = 0; i < int(n); ++i) std::tie(a[i], b[i]) = v[i];
  }
  auto check = [&](int d) {
    UnionFind uf(d + 1);
    for (int i = 0; i < int(n); ++i) {
      if (d < a[i]) return false;
      if (b[i] <= d) uf.unite(a[i], b[i]);
    }
    std::vector<int> cnt(d + 1, 0);
    for (int i = 0; i < int(n); ++i) {
      ++cnt[uf.find(a[i])];
    }
    for (int i = 0; i < int(d + 1); ++i) {
      if (cnt[i] > uf.size(i)) return false;
    }
    return true;
  };
  int ok = sz - 1, ng = 0;
  while (ok - ng > 1) {
    int me = (ok + ng) / 2;
    if (check(me))
      ok = me;
    else
      ng = me;
  }
  std::cout << ((ok == sz - 1) ? -1 : inv[ok]);
  std::cout << "\n";
  ;
  return 0;
}
