from my_input import input

h, w = map(int, input().split())

result = [r for _ in range(h) for r in input()]
score = [s for _ in range(h) for s in map(int, input().split())]

print(sum([s for r, s in zip(result, score) if r == 'o']))