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