n = int(input()) s, t = [], [] for i in range(n): te, mp = input().split() s.append(te) t.append(mp) ans = '' for i in range(n - 1, -1, -1): if s[i] == '1': ans += t[i] for i in range(n): if s[i] == '0': ans += t[i] print(ans)