#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int N = 2e5 + 5;
int n, ans = 0;
map<int, int> mp;
int get(int x) { return mp[x] = (x >= mp[x] ? x : get(mp[x])); }
void Solve() {
  cin >> n;
  int a, b;
  while (n--) {
    cin >> a >> b;
    a = get(a);
    b = get(b);
    if (a > b) swap(a, b);
    if (a > ans) ans = a;
    if (ans == INT32_MAX) break;
    mp[a] = (a == b ? INT32_MAX : b);
  }
  cout << (ans == INT32_MAX ? -1 : ans);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  Solve();
  return 0;
}
