#include <bits/stdc++.h>
using namespace std;
int freq[1010], a[1010], x[1010];
map<char, int> mp;
string s[1010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= m; i++) cin >> a[i];
  int c = 0;
  for (int i = 0; i < m; i++) {
    memset(x, 0, sizeof(x));
    for (int j = 1; j <= n; j++) {
      x[s[j][i] - 'A']++;
    }
    int maxx = 0;
    for (int j = 0; j <= 5; j++) maxx = max(maxx, x[j]);
    c += maxx * a[i + 1];
  }
  cout << c << endl;
  return 0;
}
