N = int(input())
A = [0] * 101010
for i in range(N):
    a, b = map(int, input().split())
    A[a] += 1
    A[b+1] -= 1
ans = 1
cuma = A[0]
for i, a in enumerate(A[1:], 1):
    cuma += a
    if cuma >= i-1:
        ans = i
print(ans-1)

