# https://yukicoder.me/problems/no/3797 from collections import deque def main(): N = int(input()) ab = [] for _ in range(N): a, b = map(int, input().split()) ab.append((a, b)) # 座標圧縮 a_set = {1} for a, b in ab: a_set.add(a) a_set.add(b) a_list = list(a_set) a_list.sort() a_map = {} for i , a in enumerate(a_list): a_map[a] = i a_max = len(a_list) next_nodes = [[] for _ in range(a_max)] for a, b in ab: next_nodes[a_map[a]].append(a_map[b]) for i in range(1, a_max): next_nodes[i].append(i - 1) dp = [False] * a_max dp[0] = True queue = deque() queue.append(0) while len(queue) > 0: v = queue.popleft() for w in next_nodes[v]: if not dp[w]: dp[w] = True queue.append(w) for i in reversed(range(a_max)): if dp[i]: print(a_list[i]) return if __name__ == "__main__": main()