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