#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29, MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  int a[100010] = {};
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    a[x]++;
    a[y + 1]--;
  }
  int ans = 0;
  for (int i = 0; i < 100010; i++) {
    a[i + 1] += a[i];
    if (i <= a[i] && ans < a[i]) ans = i;
  }
  cout << --ans << endl;
  return 0;
}
