#include <bits/stdc++.h>
using namespace std;
long long l, r = 8, n, b[11000], i, c[10], m, k, d, j, x, y, ma, s;
char a[11000][11000];
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> a[i][j];
  for (i = 1; i <= m; i++) cin >> b[i];
  for (i = 1; i <= m; i++) {
    c[0] = c[1] = c[2] = c[3] = c[4] = 0;
    for (j = 1; j <= n; j++) c[a[j][i] - 'A']++;
    ma = max(c[0], max(c[1], c[2]));
    ma = max(ma, max(c[3], c[4]));
    s += ma * b[i];
  }
  cout << s;
}
