#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b, ans, t;
  cin >> N;
  vector<int> A, B;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  ans = 0;
  for (int i = N + 1; i > 0; --i) {
    t = 1;
    for (int j = 0; j < N; ++j) {
      if (i >= A[j] && i <= B[j]) t++;
    }
    if (t >= i) ans = max(ans, i - 1);
  }
  cout << ans << endl;
}
