#include <bits/stdc++.h>
using namespace std;
template <class T>
void max_swap(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
  a = min(a, b);
}
const double EPS = 1e-10;
int main() {
  int n;
  static int new_ok[100010];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    ++new_ok[min(b, n + 1)];
    --new_ok[min(a - 1, n + 1)];
  }
  ++new_ok[n + 1];
  int res = -3, ok = 0;
  for (int i = n + 1; i > 0; --i) {
    if (ok) ok += new_ok[i];
    if (ok >= i) {
      res = i - 1;
      break;
    }
  }
  printf("%d\n", res);
}
