#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int a[MAX_N], b[MAX_N];
int n;
bool possible(int u) {
  int cnt = 1;
  for (int i = 0; i < n; ++i) {
    if (a[i] <= u && b[i] >= u) {
      cnt++;
      if (cnt >= u) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
  }
  int h, l;
  l = 1, h = n + 2;
  while (1) {
    int mid = (l + h) / 2;
    if (mid == l) {
      printf("%d\n", mid - 1);
      break;
    }
    if (possible(mid)) {
      l = mid;
    } else {
      h = mid;
    }
  }
  return 0;
}
