#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> parent;
  std::vector<int> height;
  std::vector<int> m_size;

 public:
  UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
    for (int i = 0; i < size_; ++i) parent[i] = i;
  }
  void init(int size_) {
    parent.resize(size_);
    height.resize(size_, 0);
    m_size.resize(size_, 0);
    for (int i = 0; i < size_; ++i) parent[i] = i;
  }
  int find(int x) {
    if (parent[x] == x) return x;
    return parent[x] = find(parent[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    int t = size(x) + size(y);
    m_size[x] = m_size[y] = t;
    if (height[x] < height[y])
      parent[x] = y;
    else
      parent[y] = x;
    if (height[x] == height[y]) ++height[x];
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) {
    if (parent[x] == x) return m_size[x];
    return size(parent[x] = find(parent[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]];
  UnionFind uf(sz);
  std::vector<int> cnt(sz, 0);
  auto check = [&](int d) {
    uf.init(sz);
    FILL(cnt, 0);
    for (int i = 0; i < int(n); ++i) {
      if (d < a[i]) return false;
      if (b[i] <= d) uf.unite(a[i], b[i]);
    }
    for (int i = 0; i < int(n); ++i) {
      ++cnt[uf.find(a[i])];
    }
    for (int i = 0; i < int(sz); ++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;
}
