#include <bits/stdc++.h>
using namespace std;
long long n, m, a[1005];
string s;
vector<string> ans;
long long dp[1005];
long long go(long long i) {
  if (i >= m) return 0;
  string tt = "ABCDE";
  long long ret = 0;
  if (dp[i] != -1) return dp[i];
  for (auto it : tt) {
    long long iska = 0;
    for (long long j = 0; j < n; j++) {
      if ((ans[j])[i] == it) iska += a[i];
    }
    ret = max(ret, iska + go(i + 1));
  }
  return dp[i] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long i, j;
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> s;
    ans.push_back(s);
  }
  for (i = 0; i < m; i++) {
    cin >> a[i];
  }
  cout << go(0);
  return 0;
}
