memo = [0]*100010
n = input()
for i in xrange(n):
    a, b = map(int, raw_input().split())
    memo[a] += 1
    memo[b+1] -= 1
ans = 0
su = 0
for i in xrange(100005):
    su += memo[i]
    if su+1>=i:
        ans = max(ans, i-1)
print ans