n=int(input())
l=[0 for i in range(100003)]
for i in range(n):
    a,b=map(int,input().split())
    l[a]+=1
    l[b+1]-=1
su=1
res=1
for i in range(100003):
    su+=l[i]
    if su>=i:
        res=max(i,res)
print(res-1)

