#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s[n];
  int a[m];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> a[i];
  int i, j, k, max, r = 0;
  for (i = 0; i < m; i++) {
    int x[5] = {0};
    for (j = 0; j < n; j++) {
      x[s[j][i] - 65]++;
    }
    max = 0;
    for (k = 0; k < 5; k++)
      if (x[k] > max) max = x[k];
    r = r + (max * a[i]);
  }
  cout << r;
}
