#include <bits/stdc++.h>
using namespace std;
long long x = 0, y = 0, n = 0, i = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string s;
  long long m = 0;
  cin >> n >> m;
  long long a[m][5], b[m];
  cin >> s;
  for (i = 0; i < m; i++) {
    for (long long j = 0; j < 5; j++) {
      a[i][j] = 0;
    }
    a[i][s[i] - 'A'] = 1;
  }
  for (i = 1; i < n; i++) {
    cin >> s;
    for (long long j = 0; j < m; j++) {
      a[j][int(s[j] - 'A')] += 1;
    }
  }
  long long k, ans = 0;
  for (i = 0; i < m; i++) {
    y = 1;
    cin >> b[i];
    for (long long j = 0; j < 5; j++) {
      y = max(y, a[i][j]);
    }
    ans += (y * b[i]);
  }
  cout << ans;
  return 0;
}
