n = int(input()) ab = sorted(tuple(map(int, input().split())) for _ in range(n)) mx = 1 for a, b in ab: if mx >= a: mx = max(mx, b) print(mx)