#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
int lg(long long x) {
  int res = 0;
  for (int i = 0; i < x; i++) {
    long long GT = (1LL << i);
    if (GT <= x) {
      res = i;
    } else {
      return res;
    }
  }
  return res;
}
long long GCD(long long a, long long b) {
  if (a == 0) {
    return abs(b);
  }
  if (b == 0) {
    return abs(a);
  }
  return GCD(b, a % b);
}
long long sqr(long long x) { return x * x; }
long long nhan(long long a, long long b, long long module) {
  a %= module;
  b %= module;
  long long q = (long double)a * b / module;
  long long r = (a * b - q * module) % module;
  if (r < 0) {
    r += module;
  }
  return r;
}
long long MU(long long a, long long n, long long module) {
  long long res = 1;
  for (; n; n = n >> 1, a = nhan(a, a, module)) {
    if (n & 1) {
      res = nhan(res, a, module);
    }
  }
  return res;
}
const int N = 1e6 + 10;
const int oo = 1e9;
const long double sodu = 1e-6;
const long long module = 1e9 + 7;
int n, m, top = 0, nlink = 0;
bool Found;
int l[N], r[N], day[N * 2], kt[N], stk[N], match[N], link[N];
vector<int> a[N];
void nhap() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    day[++m] = l[i];
    day[++m] = r[i];
  }
  sort(day + 1, day + 1 + m);
  top = 1;
  for (int i = 2; i <= m; i++) {
    if (day[i] != day[i - 1]) {
      day[++top] = day[i];
    }
  }
  m = top;
  for (int i = 1; i <= n; i++) {
    int u = lower_bound(day + 1, day + 1 + top, l[i]) - day;
    int v = lower_bound(day + 1, day + 1 + top, r[i]) - day;
    a[i].push_back(u);
    a[i].push_back(v);
  }
}
void DFS(int u) {
  for (int v : a[u]) {
    if (!kt[v]) {
      stk[++top] = v;
      kt[v] = 1;
      if (match[v] == 0) {
        Found = true;
      } else {
        DFS(match[v]);
      }
      if (Found) {
        match[v] = u;
        return;
      }
    }
  }
}
void solve() {
  for (int i = 1; i <= n; i++) {
    link[i] = i;
  }
  nlink = n;
  int Old;
  do {
    Old = nlink;
    top = 0;
    for (int i = nlink; i >= 1; i--) {
      Found = false;
      DFS(link[i]);
      if (Found) {
        link[i] = link[nlink--];
      }
    }
    for (int i = 1; i <= top; i++) {
      kt[stk[i]] = 0;
    }
  } while (Old != nlink);
  if (nlink != 0) {
    cout << -1;
    return;
  }
  for (int i = m; i >= 1; i--) {
    if (match[i]) {
      cout << day[i];
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  nhap();
  solve();
}
