#include <bits/stdc++.h>
using namespace std;
int cnt[1000][5];
int ans;
int main() {
  ios::sync_with_stdio(0);
  cout << setprecision(10) << fixed;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    int j = 0;
    for (char c : s) {
      cnt[j][c - 'A']++;
      j++;
    }
  }
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    ans += a * max(cnt[i][0],
                   max(cnt[i][1], max(cnt[i][2], max(cnt[i][3], cnt[i][4]))));
  }
  cout << ans;
  return 0;
}
