#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> st(n);
  ;
  for (long long i = 0; i < n; i++) cin >> st[i];
  int mr[m][26];
  memset(mr, 0, sizeof(mr));
  ;
  for (long long i = 0; i < m; i++) {
    ;
    for (long long j = 0; j < n; j++) {
      mr[i][st[j][i] - 'A']++;
    }
  }
  int cost = 0, ma = INT_MIN, a;
  ;
  for (long long i = 0; i < m; i++) {
    cin >> a;
    ;
    for (long long j = 0; j < 26; j++) {
      if (mr[i][j] > ma) ma = mr[i][j];
    }
    cost += ma * a;
    ma = INT_MIN;
  }
  cout << cost;
  return 0;
}
