#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, ans = 0, index;
  string s;
  cin >> n >> m;
  int cont[26] = {0};
  vector<string> v;
  vector<int> w;
  for (i = 0; i < n; i++) {
    cin >> s;
    v.push_back(s);
  }
  for (i = 0; i < m; i++) {
    cin >> j;
    w.push_back(j);
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      cont[v[j][i] - 'A']++;
    }
    index = max_element(cont, cont + 26) - cont;
    ;
    ans += w[i] * cont[index];
    for (j = 0; j < 26; j++) cont[j] = 0;
  }
  cout << ans << endl;
  return 0;
}
