#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int m, n, s = 0, a, b, c, d, e, i, j;
  cin >> n >> m;
  char an[n][2000];
  int mr[m];
  for (i = 0; i < n; i++) {
    cin >> an[i];
  }
  for (i = 0; i < m; i++) cin >> mr[i];
  for (i = 0; i < m; i++) {
    a = 0;
    b = 0;
    c = 0;
    d = 0;
    e = 0;
    for (j = 0; j < n; j++) {
      if (an[j][i] == 'A')
        a++;
      else if (an[j][i] == 'B')
        b++;
      else if (an[j][i] == 'C')
        c++;
      else if (an[j][i] == 'D')
        d++;
      else
        e++;
    }
    s += mr[i] * max(e, max(max(a, b), max(c, d)));
  }
  cout << s << endl;
  return 0;
}
