#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int c[1111];
string second[1111];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> second[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> c[i];
  }
  long long sum = 0;
  for (int i = 0; i < m; ++i) {
    map<char, int> m;
    for (int j = 0; j < n; ++j) {
      m[second[j][i] - 'A']++;
    }
    sum += max(m[0], max(m[1], max(m[2], max(m[3], m[4])))) * (c[i]);
  }
  cout << sum << endl;
}
