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