N = int(input())
P = []
for i in range(N):
    a, b = map(int, input().split())
    P.append((a, b))

Fmaxim = 0
for i in range(N+1):
    Pcount = 1
    for a, b in P:
        if a <= i+1 <= b:
            Pcount += 1
    if Pcount >= i+1:
        Fmaxim = max(Fmaxim, i)

print(Fmaxim)