#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  vector<int> ans;
  for (int j = 0; j < m; j++) {
    int x;
    cin >> x;
    ans.push_back(x);
  }
  int total = 0;
  for (int j = 0; j < m; j++) {
    int count[5], max_ans = INT_MIN;
    memset(count, 0, sizeof(count));
    for (int i = 0; i < n; i++) {
      count[v[i][j] - 65]++;
      max_ans = max(max_ans, count[v[i][j] - 65]);
    }
    total += max_ans * ans[j];
  }
  cout << total << endl;
}
