#include <bits/stdc++.h>
using namespace std;
int a[1010];
int main() {
  int n, m;
  string s[1010];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) cin >> a[i];
  int sum = 0;
  for (int i = 0; i < m; i++) {
    int cnt[10] = {0}, mx = 1;
    for (int j = 0; j < n; j++) cnt[s[j][i] - 'A']++;
    for (int i = 0; i < 5; i++) mx = max(mx, cnt[i]);
    sum += a[i] * mx;
  }
  cout << sum;
}
