#include <bits/stdc++.h>
using namespace std;

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

const int MAX = 100000;

int dp[MAX + 1] = {};

int main() {
	int n; cin >> n;
	
	int a, b, res = 0;
	REP( i, n ) {
		cin >> a >> b;
		FOR( i, a, b + 1 ) {
			dp[i]++;
			if( dp[i] == i - 1 ) res = max( dp[i], res );
		}
	}

	cout << res << endl;
}
