#include <bits/stdc++.h>
const double PI = acos(-1);
const double EPS = 1e-8;
const long long inf = 1e16;
using namespace std;
int main() {
  int n;
  cin >> n;
  int dp[100100] = {0};
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    dp[a]++;
    dp[b + 1]--;
  }
  int ma = 0;
  for (int i = 0; i < 100099; i++) dp[i + 1] += dp[i];
  for (int i = 0; i < n + 1; i++) {
    if (i - 1 <= dp[i]) ma = max(ma, i - 1);
  }
  cout << ma << endl;
}
