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