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