#include <bits/stdc++.h>
using namespace std;
int main() {
  int num[100005] = {0};
  int n, m = 0, temp;
  cin >> n;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    num[a]++;
    num[b + 1]--;
  }
  for (int i = 2; i < 10005; i++) {
    num[i] += num[i - 1];
    if (num[i] + 1 >= i) temp = i - 1;
  }
  cout << temp << endl;
}
