#include <bits/stdc++.h>
using namespace std;
int n, m, a;
string s[1002];
int k[5];
int sol = 0;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int j = 0; j < m; j++) {
    cin >> a;
    memset(k, 0, sizeof k);
    for (int i = 0; i < n; i++) {
      k[s[i][j] - 'A']++;
    }
    sol += max(k[0], max(k[1], max(k[2], max(k[3], k[4])))) * a;
  }
  cout << sol << endl;
  return 0;
}
