#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int gcd(int a, int b) {
  if (a == 0)
    return b;
  else if (b == 0)
    return a;
  if (a < b)
    return gcd(a, b % a);
  else
    return gcd(b, a % b);
}
void solve() {
  int n, m;
  cin >> n >> m;
  string s[n];
  int f[1005][5] = {0};
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      f[j][s[i][j] - 'A']++;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> x;
    int t = 0;
    for (int j = 0; j < 5; j++) {
      t = max(t, f[i][j]);
    }
    ans += t * x;
  }
  cout << ans << endl;
}
int main() {
  std ::ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout.precision(10);
  solve();
}
