#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int in[N];
int de[N];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < N; i++) in[i] = 0, de[i] = 0;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      in[a]++;
      de[b + 1]++;
    }
    int ans = 0;
    int now = 0;
    for (int i = 0; i < N; i++) {
      now += in[i];
      now -= de[i];
      if (now >= i) ans = i;
    }
    if (ans != 0) ans--;
    cout << ans << endl;
  }
}
