#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  int a, b;
  vector<pair<int, int> > box;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    box.push_back(pair<int, int>(a, b));
  }
  sort(box.begin(), box.end());
  for (int i = 1; i <= n + 1; i++) {
    vector<int> vec;
    for (int j = 0; j < n; j++) {
      if (i >= box[j].first) {
        vec.push_back(box[j].second);
      } else
        break;
    }
    sort(vec.begin(), vec.end());
    int t = 0;
    for (int k = 0; vec.size() > k; k++) {
      if (i <= vec[k]) {
        t++;
      }
    }
    if (t + 1 < i) continue;
    ans = max(ans, i - 1);
    if (t == 0) ans = max(ans, 0);
    vec.clear();
  }
  cout << ans << endl;
  return 0;
}
