n = int(input())
li = [0] * 100003
ans = 0

for i in range(n):
    a,b = map(int,input().split())
    li[a] += 1
    li[b + 1] -= 1

for i in range(1,len(li)):
    li[i] += li[i-1]
    if i -1 <= li[i]:
        ans = i-1
print(ans)
