#include <bits/stdc++.h>
int main() {
  int n, a, i;
  int x[100012], y[100012];
  int ans;
  scanf("%d", &n);
  for (a = 1; a <= n; a++) {
    scanf("%d%d", &x[a], &y[a]);
  }
  for (a = n; a > 1; a--) {
    ans = 1;
    for (i = 1; i <= n; i++) {
      if (x[i] <= a && y[i] >= a) ans++;
    }
    if (a <= ans) break;
  }
  printf("%d\n", a - 1);
  exit(0);
}
