#include <bits/stdc++.h>
using namespace std;
int c[6];
int main() {
  string s, s1 = "";
  int n, m, k = 0, mx = 0, s2 = 0;
  cin >> n >> m;
  int a[m + 1], b[m + 1];
  for (int i = 1; i <= n; i++) {
    cin >> s;
    s1 += s;
    s1 += ' ';
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < s.size(); i++) {
    k = 0;
    c[1] = c[2] = c[3] = c[4] = c[5] = 0;
    for (int j = i; j < s1.size(); j += s.size() + 1) {
      if (s1[j] == 'A') {
        c[1]++;
      }
      if (s1[j] == 'B') {
        c[2]++;
      }
      if (s1[j] == 'C') {
        c[3]++;
      }
      if (s1[j] == 'D') {
        c[4]++;
      }
      if (s1[j] == 'E') {
        c[5]++;
      }
    }
    sort(c + 1, c + 5 + 1);
    b[i + 1] = c[5];
  }
  for (int i = 1; i <= m; i++) {
    s2 += a[i] * b[i];
  }
  cout << s2;
}
