N = int(input())
P = []
bmax = 0
for i in range(N):
    a, b = map(int, input().split())
    bmax = max(bmax, b)
    if a <= N+1:
        P.append((a, b))
if len(P) > 0:
    for i in range(min(len(P), bmax), -1, -1):
        Pcount = 1
        for a, b in P:
            if a <= i+1 <= b:
                Pcount += 1
        if Pcount >= i+1:
            print(i)
            break
else:
    print('0')