#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ab(100002);
vector<int> k(100002);
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < 100002; i++) {
    ab[i].first = 0;
    ab[i].second = 0;
  }
  for (int i = 1; i <= N; i++) {
    cin >> ab[i].first >> ab[i].second;
    k[ab[i].first]++;
    k[ab[i].second]--;
  }
  int sum = 0;
  int ans = 0;
  for (int i = 1; i < 100002; i++) {
    sum += k[i];
    if (sum + 1 >= i) {
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}
