#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
int main() {
  cin >> n;
  for (int i = 0, s, t; i < n; i++) cin >> s >> t, a[s - 1]++, a[t - 1]--;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    a[i] += a[i - 1];
    if (i <= a[i]) ans = max(i, ans);
  }
  cout << ans << endl;
  return 0;
}
