#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int result[100003] = {};
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    result[l]++;
    result[r + 1]--;
  }
  int ans = 0;
  for (int i = 2; i < n + 1; i++) {
    result[i] += result[i - 1];
    if (result[i] + 1 >= i) ans = max(i + 1, ans);
  }
  if (ans > 0) ans--;
  cout << ans << endl;
  return 0;
}
