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