#include <bits/stdc++.h>
using namespace std;
string b[200007];
int a[200007];
int cnt[10];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (auto i = (1); i <= (n); ++i) cin >> b[i];
  for (auto i = (1); i <= (m); ++i) scanf("%d", &a[i]);
  int ans = 0;
  for (auto i = (1); i <= (m); ++i) {
    for (auto j = (1); j <= (n); ++j) ++cnt[b[j][i - 1] - 'A'];
    ans += a[i] * max({cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]});
    cnt[0] = cnt[1] = cnt[2] = cnt[3] = cnt[4] = 0;
  }
  printf("%d\n", ans);
  return 0;
}
