#include <bits/stdc++.h>
using namespace std;
int cnt[1001][5];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  string s;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    for (int j = 0; j < s.length(); ++j) {
      cnt[j][s[j] - 'A']++;
    }
  }
  int ans = 0;
  int score;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &score);
    int cur = cnt[i][0];
    for (int j = 1; j < 5; ++j) {
      cur = max(cur, cnt[i][j]);
    }
    ans += score * cur;
  }
  printf("%d\n", ans);
  return 0;
}
