N = int(input())
R = [0 for i in range(100003)]
for i in range(N):
    a, b = map(int, input().split())
    R[a] += 1
    R[b+1] -= 1
x = 1
y = 1
for i in range(100003):
    x += R[i]
    if x >= i:
        y = max(i, y)
print(y-1)
