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