#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int a, b;
  int dp[100010] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    dp[min(a, n + 1)]++;
    dp[min(b + 1, n + 1)]--;
  }
  int ret = 0;
  for (int i = 0; i < 100009; i++) {
    dp[i + 1] += dp[i];
    if (i - 1 <= dp[i]) ret = max(ret, i - 1);
  }
  cout << ret << endl;
}
