x,y=map(int,input().split()) gd={} for i in range(x): s=input().split() gd[int(s[0])]=s[1] for i in range(y): print(gd[int(input())],end=" ")