#include <bits/stdc++.h>
using namespace std;
char c;
int a[1010][5], p, cnt, n, m;
long long ans;
int main() {
  scanf("%d%d", &n, &m);
  char aa = getchar();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%c", &c);
      a[j][c - 'A']++;
    }
    char aa = getchar();
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &p);
    cnt = 0;
    for (int j = 0; j < 5; j++) {
      if (a[i][j] > cnt) cnt = a[i][j];
    }
    ans += (long long)cnt * (long long)p;
  }
  printf("%lld\n", ans);
  return 0;
}
