#include <bits/stdc++.h>
using namespace std;
char examAnswers[1000 + 5][1000 + 5];
int maxCorr[1000 + 5];
int main() {
  int n, m, ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", examAnswers[i]);
  for (int i = 0; i < m; i++) {
    int acount, bcount, ccount, dcount, ecount;
    acount = bcount = ccount = dcount = ecount = 0;
    for (int j = 0; j < n; j++) {
      if (examAnswers[j][i] == 'A')
        acount++;
      else if (examAnswers[j][i] == 'B')
        bcount++;
      else if (examAnswers[j][i] == 'C')
        ccount++;
      else if (examAnswers[j][i] == 'D')
        dcount++;
      else
        ecount++;
    }
    maxCorr[i] = max(max(max(acount, bcount), max(ccount, dcount)), ecount);
  }
  for (int i = 0; i < m; i++) {
    int w;
    scanf("%d", &w);
    ans += w * maxCorr[i];
  }
  printf("%d", ans);
}
