# 读取输入 n, m = map(int, input().split()) # 项目总数,小A参加的项目数 happiness = list(map(int, input().split())) # 每个项目的欢乐度 attended_projects = list(map(int, input().split())) # 小A参加的项目编号 # 计算小A的总欢乐度 total_happiness = sum(happiness[i - 1] for i in attended_projects) # 输出结果 print(total_happiness)