#include <bits/stdc++.h>
using namespace std;
int fq[5];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  string str[n];
  for (int i = 0; i < n; i++) cin >> str[i];
  int arr[m], mx = INT_MIN, pos;
  string a = "";
  for (int i = 0; i < m; i++) cin >> arr[i];
  for (int i = 0; i < m; i++) {
    mx = INT_MIN, pos = 0;
    for (int j = 0; j < 5; j++) fq[j] = 0;
    for (int j = 0; j < n; j++) {
      fq[str[j][i] - 'A']++;
    }
    for (int j = 0; j < 5; j++) {
      if (fq[j] > mx) {
        pos = j;
        mx = max(mx, fq[j]);
      }
    }
    a += 'A' + pos;
  }
  int total = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[j] == str[i][j]) total += arr[j];
    }
  }
  printf("%d\n", total);
  return 0;
}
