#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef pair<int, int> pii;

int N, A, B;
int s[200000];

int main(void) {
  cin >> N;
  REP(i, 0, N + 2) s[i] = 0;
  REP(i, 0, N) {
    cin >> A >> B;
    s[A - 1]++;
    s[B]--;
  }
  REP(i, 1, 100001) s[i] += s[i - 1];

  int ans = 0;
  REP(i, 0, N + 2) if(i <= s[i]) ans = i;
  cout << ans << endl;

  return 0;
}