HZNUOJ


Problem_ID: G
Result: Accepted
Time: 778ms
Memory: 25568kB
Author: 13115729003
In contest: 1300

n,t=map(int,input().split())
a=list(input().split())
for i in range(t):
    x,y=map(str,input().split())
    if y in a:
        a.insert(a.index(y),x)
print(" ".join(a))