#include <bits/stdc++.h>
using namespace std;
const int MAX = 100002;
int main() {
  int n, ans[MAX], a, b;
  int MX = -1 << 27;
  fill(ans, ans + MAX, 0);
  cin >> n;
  while (n--) {
    cin >> a >> b;
    MX = max(MX, b);
    for (int i = a; i <= b; i++) ++ans[i];
  }
  int fri = 0;
  for (int i = 2; i <= MX; i++) {
    if (ans[i] + 1 > i) fri = i - 1;
  }
  cout << fri << endl;
  return 0;
}
