#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(100000 + 2, 0);
  for (int i = 0; i < n; ++i) {
    int a;
    int b;
    cin >> a >> b;
    for (int j = a; j <= b; ++j) {
      v[j] += 1;
    }
  }
  int max_{0};
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] != 0 && i <= v[i]) {
      max_ = i - 1;
    }
  }
  cout << max_ << endl;
}
