N = int(input()) AB = [tuple(map(int, input().split(" "))) for _ in range(N)] AB.sort() H = 1 for A, B in AB: if A <= H: H = max(H, B) print(H)