n,t = map(int,input().split())
lst = list(map(int,input().split()))
for i in range(t):
x,y = map(int,input().split())
for j in range(len(lst)):
if y == lst[j]:
lst.insert(j,x)
break
for i in lst:
print(i,end = ' ' if i != lst[-1] else '')