n , m = list(map(int,input().split(" ")))
a = []
b = []
for i in range(n):
a.append(input())
for i in range(m):
b.append(input())
for i in b:
c = a.count(i)
if c == 0:
print("-1")
continue
for n,j in enumerate(a):
if i == j :
print(n+1,end=" ")
print()