#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, point[1001], A = 0, B = 0, C = 0, D = 0, E = 0;
  cin >> n >> m;
  char c[1001][1001];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> c[i][j];
  for (int i = 0; i < m; i++) {
    A = 0, B = 0, C = 0, D = 0, E = 0;
    for (int j = 0; j < n; j++) {
      if (c[j][i] == 'A')
        A++;
      else if (c[j][i] == 'B')
        B++;
      else if (c[j][i] == 'C')
        C++;
      else if (c[j][i] == 'D')
        D++;
      else if (c[j][i] == 'E')
        E++;
    }
    int ma = max(E, max(D, max(C, max(B, A))));
    point[i] = ma;
  }
  int sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> A;
    sum += point[i] * A;
  }
  cout << sum;
  return 0;
}
