#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return (b > 0) ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return (a * b == 0) ? 0 : (a * b) / gcd(a, b);
}
void solution() {
  int students, ques;
  cin >> students >> ques;
  const int N = students * ques;
  vector<char> ans(N);
  for (int i = 0; i < N; ++i) {
    cin >> ans[i];
  }
  vector<int> freq;
  int trn = 0;
  while (trn < ques) {
    int mx = 0;
    pair<char, int> cnt[] = {{'A', 0}, {'B', 0}, {'C', 0}, {'D', 0}, {'E', 0}};
    for (int i = trn; i < N; i += ques) {
      for (int j = 0; j < 5; ++j) {
        if (ans[i] == cnt[j].first) {
          cnt[j].second++;
          break;
        }
      }
    }
    for (int i = 0; i < 5; ++i) {
      mx = max(cnt[i].second, mx);
    }
    freq.push_back(mx);
    trn++;
  }
  vector<int> marks(ques);
  for (int i = 0; i < ques; ++i) {
    cin >> marks[i];
  }
  int res = 0;
  for (int i = 0; i < ques; ++i) {
    res += marks[i] * freq[i];
  }
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    solution();
  }
}
