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