#include <bits/stdc++.h>
using namespace std;
int counter[1005][5];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  while (n--) {
    char tmp;
    for (int i = 0; i < m; i++) {
      scanf(" %c", &tmp);
      counter[i][tmp - 'A'] += 1;
    }
  }
  int tpoints = 0, mpoints = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d", &tpoints);
    int ma = 0;
    for (int j = 0; j < 5; j++) ma = max(ma, counter[i][j]);
    mpoints += ma * tpoints;
  }
  printf("%d\n", mpoints);
  return 0;
}
