#include <bits/stdc++.h>
using namespace std;
int A[1000 + 113], B[1000 + 113], C[1000 + 113], D[1000 + 113], E[1000 + 113];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] == 'A') {
        A[j + 1]++;
      }
      if (s[j] == 'B') {
        B[j + 1]++;
      }
      if (s[j] == 'C') {
        C[j + 1]++;
      }
      if (s[j] == 'D') D[j + 1]++;
      if (s[j] == 'E') E[j + 1]++;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= m; ++i) {
    int x;
    cin >> x;
    ans += max(max(max(max(A[i], B[i]), C[i]), D[i]), E[i]) * x;
  }
  cout << ans;
  return 0;
}
