a=1 for A,B in sorted(list(map(int,input().split()))for i in[0]*int(input())):a=max(a,B*(a>=A)) print(a)