n = int(input()) S = [] T = [] for _ in range(n): s, t = input().split() if s == "0": T.append(t) else: S.append(t) ans = S[::-1] + T print(*ans, sep="")