#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
int x[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    x[a]++;
    x[b + 1]--;
  }
  int cnt = 1, ans = 0;
  for (int i = 0; i < n + 1; i++) {
    cnt += x[i];
    if (i <= cnt) ans = max(ans, i - 1);
  }
  cout << ans << endl;
  return 0;
}
