N = int(input())
a=[]
p = 0
for i in range(N):
    q=[int(j) for j in input().split()]
    a.append([q[0]-1,q[1]])
    p = max(p, q[1])

table=[0]*(p+1)
for i in range(len(a)):
    table[a[i][0]]+=1
    table[a[i][1]]-=1

for i in range(1,p+1):
    table[i]+=table[i-1]

ans=0
for i, val in enumerate(table):
    if val >= i and i <= N:
        ans = max(i, ans)

print(ans)

