#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, t, ma, sum = 0;
  std::string s[1000];
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < k; i++) {
    cin >> t;
    ma = 1;
    map<char, int> m;
    for (int j = 0; j < n; j++) m[s[j][i]]++;
    for (map<char, int>::iterator it = m.begin(); it != m.end(); it++)
      ma = max(ma, it->second);
    sum += ma * t;
  }
  cout << sum;
}
