N = int(input()) AB = [tuple(map(int,input().split())) for i in range(N)] ans = 1 AB.sort() for a,b in AB: if ans >= a: ans = max(ans, b) print(ans)