N=int(input()) A,B,Z,Y=[],[],'','0' for _ in range(N): T,S=input().split() A+=[S,Z][T==Y] B+=[S,Z][T!=Y] print(Z.join(A[::-1]+B))