#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int s[100002] = {};
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    for (int j = a; j <= b; ++j) ++s[j];
  }
  int ans = 0;
  for (int i = 0; i <= n + 1; ++i)
    if (i == s[i]) ans = i;
  printf("%d\n", max(ans - 1, 0));
  return 0;
}
