#include <bits/stdc++.h>
using namespace std;
int n, m, f[100050][5], x, ans = 0, cur;
string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) f[i][j] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int i = 0; i < s.length(); i++) f[i][s[i] - 'A']++;
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    cur = max(f[i][0], f[i][1]);
    cur = max(cur, f[i][2]);
    cur = max(cur, f[i][3]);
    cur = max(cur, f[i][4]);
    ans += cur * x;
  }
  cout << ans << "\n";
  return 0;
}
