#include <bits/stdc++.h>
using namespace std;
char test[1020][1020];
long long num[5], rew[1020];
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> test[i][j];
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> rew[i];
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i) {
      num[test[i][j] - 65]++;
    }
    long long m = 0;
    for (int i = 0; i < 5; ++i) {
      m = max(m, num[i]);
      num[i] = 0;
    }
    ans += m * rew[j];
  }
  cout << ans;
}
