#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  t = 1;
  while (t--) {
    int n, m;
    int b = 0, c = 0;
    cin >> n >> m;
    int arr[5][m];
    memset(arr, 0, sizeof(arr));
    int i = 0;
    while (i < n) {
      string s;
      cin >> s;
      for (int j = 0; j < m; j++) {
        arr[s[j] - 'A'][j]++;
      }
      i++;
    }
    int a[m];
    for (int i = 0; i < m; i++) cin >> a[i];
    int ans = 0;
    for (int j = 0; j < m; j++) {
      int r = 0;
      for (int i = 0; i < 5; i++) {
        r = ((r < arr[i][j]) ? arr[i][j] : r);
      }
      ans += r * a[j];
    }
    cout << ans << "\n";
  }
  return 0;
}
