#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s[n];
  int marks[m], result = 0, count[5];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> marks[i];
  for (int i = 0; i < m; i++) {
    for (int i = 0; i < 5; i++) count[i] = 0;
    for (int j = 0; j < n; j++) count[s[j][i] - 65]++;
    sort(count, count + 5);
    result += (count[4] * marks[i]);
  }
  cout << result;
  return 0;
}
