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