#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define rep(i, j, k) for (auto i = j; i < k; i++)
#define rrep(i, j, k) for (auto i = j; i > k; i--)
using namespace std;

int sum[100011];

int main() {
  int n; cin >> n;
  rep(i, 0, n) {
    int a, b; cin >> a >> b;
    sum[a]++;
    sum[b + 1]--;
  }
  rep(i, 1, 100011) sum[i] = sum[i] + sum[i - 1];
  int _max = 0;
  rep(i, 0, 100011) {
    if (sum[i] >= i - 1) _max = max(_max, i - 1);
  }
  cout << _max << endl;
}


