#include <bits/stdc++.h>
using namespace std;
int main() {
  int s = 0;
  vector<vector<int>> A;
  vector<int> o(5);
  vector<int> a;
  int n, m;
  cin >> n >> m;
  A.resize(n);
  for (int i = 0; i < n; i++) {
    A[i].resize(m);
    for (int j = 0; j < m; j++) {
      char t;
      cin >> t;
      A[i][j] = t - 'A';
    }
  }
  a.resize(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 5; j++) {
      o[j] = 0;
    }
    for (int j = 0; j < n; j++) {
      o[A[j][i]]++;
    }
    s += a[i] * max(max(max(o[0], o[1]), max(o[2], o[3])), o[4]);
  }
  cout << s;
}
