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