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