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