#include <bits/stdc++.h>
using namespace std;
static int member[100004];
void solve() {
  int n, a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    member[a]++;
    member[b + 1]--;
  }
  partial_sum(begin(member), end(member), begin(member));
  for (int i = 1e6 + 1; i > 0; i--) {
    if (member[i] >= i - 1) {
      cout << i - 1 << "\n";
      return;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  solve();
}
