#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<string> v;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  long long a[m], sum = 0;
  for (long long i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (n == 1) {
    cout << sum << endl;
    return 0;
  }
  for (long long i = 0; i < m; i++) {
    long long f[26] = {0};
    for (long long j = 0; j < n; j++) {
      f[v[j][i] - 'A']++;
    }
    long long mx = 0;
    for (long long j = 0; j < 26; j++) {
      mx = max(mx, f[j]);
    }
    sum += (mx - 1) * a[i];
  }
  cout << sum << endl;
  return 0;
}
