#include <bits/stdc++.h>
using namespace std;
void CyBerForCe() {
  long long n, m;
  cin >> n >> m;
  string s[n];
  for (long long i = 0; i < n; i++) cin >> s[i];
  long long a[m], sum = 0, ma = 0;
  for (long long i = 0; i < m; i++) cin >> a[i];
  vector<long long> v;
  for (long long i = 0; i < m; i++) {
    long long f[6] = {0};
    for (long long j = 0; j < n; j++) {
      f[s[j][i] - 'A']++;
      ma = max(ma, f[s[j][i] - 'A']);
    }
    v.push_back(ma);
    ma = 0;
  }
  for (long long i = 0; i < m; i++) sum += (a[i] * v[i]);
  cout << sum << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  CyBerForCe();
  return 0;
}
