#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  int n;
  cin >> n;
  int a[100000], b[100000];
  for (i = 0; i < n; ++i) cin >> a[i] >> b[i];
  int mn = 1, mx = n + 2;
  while (mn + 1 != mx) {
    int ct = 1;
    for (i = 0; i < n; ++i) {
      if (a[i] <= (mn + mx) / 2 && (mn + mx) / 2 <= b[i]) ++ct;
    }
    if (ct < (mn + mx) / 2)
      mx = (mn + mx) / 2;
    else
      mn = (mn + mx) / 2;
  }
  cout << mn - 1 << endl;
  return 0;
}
