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