n, m = map(int, input().split())
cards = list(map(int, input().split()))
indices = list(map(int, input().split()))
def is_prime(y):
if y < 2:
return False
for i in range(2, int(y**0.5) + 1):
if y % i == 0:
return False
return True
selected_cards = [cards[i-1] for i in indices]
prime_sum = sum(card for card in selected_cards if is_prime(card))
print(prime_sum)