#include <bits/stdc++.h>
using namespace std;
vector<long> a(100002);
vector<long> b(100002);
vector<long> k(100002);
vector<long> s(100002);
int main() {
  int N;
  cin >> N;
  for (int i = 1; i < N + 1; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i < 100002; i++) {
    k[i] = i;
  }
  for (int i = 1; i < 100002; i++) {
    for (int j = a[i]; j <= b[i]; j++) {
      s[i]++;
    }
  }
  int max_o = 0;
  for (int i = 1; i < 100002; i++) {
    if (s[i] + 1 >= k[i]) {
      max_o = k[i] - 1;
    }
  }
  cout << max_o << endl;
  return 0;
}
