#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b, l, r, 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);
  }
  l = 1;
  r = N + 2;
  while (r - l > 1) {
    t = 1;
    for (int i = 0; i < N; ++i) {
      if ((r + l) / 2 >= A[i] && (r + l) / 2 <= B[i]) t++;
    }
    if (t >= (r + l) / 2)
      l = (r + l) / 2;
    else
      r = (r + l) / 2;
  }
  cout << l - 1 << endl;
}
