#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<int> a(m);
  for (int i = 0; i < m; i++) cin >> a[i];
  vector<int> num;
  long long sum = 0;
  for (int i = 0; i < m; i++) {
    num.erase(num.begin(), num.end());
    num.resize(5, 0);
    for (int j = 0; j < n; j++) {
      num[((int)s[j][i]) - 65]++;
    }
    int k = 0, ind = 0;
    for (int l = 0; l < 5; l++) {
      if (num[l] > k) {
        k = num[l];
        ind = l;
      }
    }
    sum += num[ind] * a[i];
  }
  cout << sum << endl;
  return 0;
}
