import sys
from collections import defaultdict
n,m=tuple(map(int, input().split()))
AB = sys.stdin.readlines()
A=[AB[k].split()[0] for k in range(n)]
B=[AB[k].split()[0] for k in range(n,n+m)]
indices = defaultdict(list)
for y in B:
if y in A:
for k in range(n):
if y == A[k]:
indices[y].append(k+1)
else:
indices[y].append(-1)
for y in B:
print(*indices[y])