#include <bits/stdc++.h>
using namespace std;
int c[100002];
int main() {
  int a, b, n, sum = 0;
  while (cin >> n) {
    int mab = 0;
    fill(c, c + 100002, 0);
    for (int z = 0; z < n; z++) {
      cin >> a >> b;
      for (int i = a; i <= b; i++) {
        c[i]++;
        mab = max(mab, c[i]);
      }
    }
    for (int i = mab; i >= 1; i--) {
      if (c[i] >= i) {
        cout << --i << endl;
        goto stop;
      }
    }
    cout << 0 << endl;
  stop:;
  }
}
