#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  pair<int, int> fri[n];
  for (int i = 0; i < n; i++) cin >> fri[i].first >> fri[i].second;
  int le = 0, ri = 100100;
  while (ri - le > 1) {
    int mid = (le + ri) / 2;
    int cnt = 1;
    for (int j = 0; j < n; j++) {
      if (fri[j].first <= mid && mid <= fri[j].second) cnt++;
    }
    if (cnt >= mid)
      le = mid;
    else
      ri = mid;
  }
  cout << le - 1 << endl;
  return 0;
}
