#include <bits/stdc++.h>
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> fri(100002, 0);
  int first, end, max_friend = 0;
  for (int i = 0; i < (n); i++) {
    cin >> first >> end;
    fri[first]++;
    fri[end + 1]--;
  }
  for (int i = 1; i < 100001; i++) {
    fri[i] += fri[i - 1];
    if (fri[i] >= i - 1) max_friend = max(i - 1, max_friend);
  }
  cout << max_friend << endl;
  return 0;
}
