#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5;
string s[1005];
long long f[1001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n, m;
  long long a, b, c, d, e, sum = 0, i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= m; i++) cin >> f[i];
  for (j = 0; j < m; j++) {
    int Ca = 0, Cb = 0, Cc = 0, Cd = 0, Ce = 0;
    for (i = 1; i <= n; i++) {
      if (s[i][j] == 'A')
        Ca++;
      else if (s[i][j] == 'B')
        Cb++;
      else if (s[i][j] == 'C')
        Cc++;
      else if (s[i][j] == 'D')
        Cd++;
      else if (s[i][j] == 'E')
        Ce++;
    }
    sum += f[j + 1] * max(Ca, max(Cb, max(Cc, max(Cd, Ce))));
  }
  cout << sum;
  return 0;
  return 0;
}
