https://www.acmicpc.net/problem/1620
import sys
ipt = sys.stdin.readline
opt = sys.stdout.write
n, m = map(int, ipt().split())
pocketmon_list = ['']
pocketmon_dict = dict()
for i in range(1, n+1):
name = ipt().rstrip()
pocketmon_list.append(name)
pocketmon_dict[name] = i
for i in range(m):
temp = ipt().rstrip()
if temp.isdigit():
opt(f'{pocketmon_list[int(temp)]}\n')
else:
opt(f'{pocketmon_dict[temp]}\n')