#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int N;
  cin >> N;
  vector<int> c(N + 1, 0);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    c[a - 1]++;
    c[b]--;
  }
  int sum = 0, ans = 0;
  for (int i = 1; i <= N; i++) {
    sum += c[i];
    if (i <= sum) ans = i;
  }
  cout << ans << endl;
}
