#include <bits/stdc++.h>
using namespace std;
int main() {
  int friends[100005] = {};
  int i;
  int n;
  int a, b;
  int max = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    friends[a]++;
    friends[b + 1]--;
  }
  for (i = 1; i < 100000; i++) friends[i] += friends[i - 1];
  for (i = 0; i < 100000; i++)
    if (friends[i] >= i - 1) max = i - 1;
  cout << max << endl;
}
