#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const double eps = 1e-8;
const int MAX = 1e6 + 10;
const int MAXN = 1e3 + 10;
const double pi = acos(-1.0);
const int inf = 0x7f7f7f7f;
const long long INF = 0x7f7f7f7f7f7f7f7f;
struct node {
  int a, b;
} p[MAX];
bool com(const node a, const node b) {
  if (a.a == b.a) return a.b < b.b;
  return a.a < b.a;
}
int n;
map<int, int> Mymap;
bool comm(const node a, const node b) {
  if (a.b == b.b) {
    return a.a > b.a;
  }
  return a.b > b.b;
}
bool vis[MAX];
bool judge(int xx) {
  memset(vis, 0, sizeof vis);
  for (int i = 0; i < n; i++) {
    if (p[i].b <= xx) {
      if (!vis[Mymap[p[i].b]]) {
        vis[Mymap[p[i].b]] = 1;
      } else {
        if (!vis[Mymap[p[i].a]]) {
          vis[Mymap[p[i].a]] = 1;
        } else {
          return false;
        }
      }
    } else if (p[i].b > xx && p[i].a <= xx) {
      if (!vis[Mymap[p[i].a]]) {
        vis[Mymap[p[i].a]] = 1;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
  return true;
}
int main() {
  scanf("%d", &n);
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i].a);
    scanf("%d", &p[i].b);
    if (Mymap[p[i].a] == NULL) {
      Mymap[p[i].a] = cnt++;
    }
    if (Mymap[p[i].b] == NULL) {
      Mymap[p[i].b] = cnt++;
    }
  }
  sort(p, p + n, com);
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    if (i + 1 < n && p[i].a == p[i + 1].a) {
      if (p[i].b == p[i + 1].b) {
        if (i + 2 < n && p[i + 1].a == p[i + 2].a) {
          if (p[i + 1].b == p[i + 2].b) {
            flag = 1;
            break;
          }
        }
      }
    }
  }
  if (flag) {
    printf("-1\n");
  } else {
    sort(p, p + n, comm);
    int l = 1, r = 1000000001;
    int mid;
    while (l <= r) {
      mid = (l + r) / 2;
      if (judge(mid)) {
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    if (Mymap[l] == NULL) {
      if (Mymap[l + 1] != NULL)
        l++;
      else {
        l--;
      }
    }
    printf("%d\n", l);
  }
  return 0;
}
