#include <bits/stdc++.h>
using namespace std;
bool possible(int num, vector<int> &a, vector<int> &b) {
  int cnt = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] <= num && num <= b[i]) {
      cnt++;
    }
  }
  if (cnt >= num)
    return true;
  else
    return false;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  int lb = 0;
  int ub = n + 1;
  while (ub - lb > 1) {
    int mid = (ub + lb) / 2;
    if (possible(mid, a, b)) {
      lb = mid;
    } else {
      ub = mid;
    }
  }
  cout << lb << endl;
  return 0;
}
