#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  long long int ar[n][m];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      char ch;
      cin >> ch;
      long long int df = ch - 'A';
      ar[i][j] = df;
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < m; i++) {
    long long int x;
    cin >> x;
    long long int a = 0;
    long long int b = 0;
    long long int c = 0;
    long long int d = 0;
    long long int e = 0;
    for (long long int j = 0; j < n; j++) {
      if (ar[j][i] == 0) {
        a++;
      } else if (ar[j][i] == 1) {
        b++;
      } else if (ar[j][i] == 2) {
        c++;
      } else if (ar[j][i] == 3) {
        d++;
      } else {
        e++;
      }
    }
    long long int u = max(a, max(b, max(c, max(d, e))));
    ans += u * x;
  }
  cout << ans;
  return 0;
}
