#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int num[100002];
  int sum;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      num[j]++;
    }
  }
  for (int i = N + 1; i > 0; i--) {
    if (num[i] >= i - 1) {
      cout << i - 1 << endl;
      break;
    }
  }
  return 0;
}
