#include <bits/stdc++.h>
int a[1010], b[1010][1010], n, m, ans, sum;
char ch;
int main() {
  std::cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      std::cin >> ch;
      b[i][j] = ch - 'A' + 1;
    }
  }
  for (int i = 1; i <= m; ++i) std::cin >> a[i];
  for (int i = 1; i <= m; ++i) {
    sum = 0;
    for (int k = 1; k <= 5; ++k) {
      int s = 0;
      for (int j = 1; j <= n; ++j) {
        if (k == b[j][i]) s += a[i];
      }
      sum = std::max(sum, s);
    }
    ans += sum;
  }
  std::cout << ans << std::endl;
  return 0;
}
