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