n=int(input())
t=[0]*1000002

for i in range(n):
    a,b=map(int,input().split())
    t[a-1]+=1
    t[b]-=1
    
ans=0
for i in range(1000002):
    t[i]+=t[i-1]
    if i<=t[i]:
        ans=i

print(ans)
