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