#include <bits/stdc++.h>
const int MX = 1e5 + 100;
using namespace std;
string s[999999], x, c;
long long a[999999];
long long n, m, k, q, t, w, e, r, l;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  while (m != k) {
    for (int i = 0; i < n; i++) {
      c = s[i];
      if ('A' == c[k]) t++;
      if ('B' == c[k]) e++;
      if ('C' == c[k]) w++;
      if ('D' == c[k]) r++;
      if ('E' == c[k]) l++;
    }
    long long mx = max(t, max(e, max(w, max(r, l))));
    k++;
    q += mx * a[k];
    t = 0;
    mx = 0;
    e = 0;
    w = 0;
    r = 0;
    l = 0;
  }
  cout << q;
  getchar();
  getchar();
  return 0;
}
