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