#include <iostream>
#define MAX 100002
using namespace std;

int range[MAX][3];
int number[MAX];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> range[i][0] >> range[i][1];
    range[i][2] = 1;
  }
  
  for (int i = 2; i <= MAX; i++)
    number[i] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = range[i][0]; j <= range[i][1]; j++) {
      number[j]++;
    }
  }

  int ans = 0;
  for (int i = 2; i <= n + 1; i++) {
    if (number[i] >= i) ans = i - 1;
  }
  cout << ans << endl;
    
  return 0;
}