#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[1005], b[1005], c[1005], d[1005], e[1005];
int p[1005], n, m, x, ans;
char st[1005][1005], cc;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> cc;
      if (cc == 'A') a[j]++;
      if (cc == 'B') b[j]++;
      if (cc == 'C') c[j]++;
      if (cc == 'D') d[j]++;
      if (cc == 'E') e[j]++;
    }
  }
  for (int i = 1; i <= m; i++) cin >> p[i];
  for (int i = 1; i <= m; i++) {
    x = max(a[i], max(b[i], max(c[i], max(d[i], e[i])))) * p[i];
    ans += x;
  }
  cout << ans << endl;
  return 0;
}
