#include <bits/stdc++.h>
using namespace std;
pair<int, int> friends[100001];
int dp[100001];
int N;
bool check(int m) {
  m++;
  int cnt = 0;
  for (int i = 0; i < N; i++)
    if (friends[i].first <= m && friends[i].second >= m) cnt++;
  return (cnt >= (m - 1));
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> friends[i].first >> friends[i].second;
  int lb = 0;
  int ub = N + 1;
  while (ub - lb > 1) {
    int mid = (ub + lb) / 2;
    if (check(mid))
      lb = mid;
    else
      ub = mid;
  }
  cout << lb << endl;
  return 0;
}
