#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t = 0, x = 1, score = 0, Max = 1;
  cin >> n >> m;
  int *p = new int[m];
  string *s;
  s = new string[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> p[i];
  for (int k = 0; k < m; k++) {
    for (int i = 0; i < n; i++) {
      if (s[i][t] != -1)
        for (int j = i + 1; j < n; j++)
          if (s[i][t] == s[j][t]) {
            x++;
            s[j][t] = -1;
          }
      Max = max(Max, x);
      x = 1;
    }
    score += Max * p[k];
    Max = 1;
    t++;
  }
  cout << score;
}
