#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  string ans[n];
  for (long long i = 0; i < n; i++) {
    cin >> ans[i];
  }
  vector<long long> marks(m);
  for (long long i = 0; i < m; i++) cin >> marks[i];
  long long cnt = 0;
  for (long long i = 0; i < m; i++) {
    map<char, long long> mp;
    long long mxx = 0;
    for (long long j = 0; j < n; j++) {
      mp[ans[j][i]]++;
      mxx = max(mxx, mp[ans[j][i]]);
    }
    long long fre = mxx;
    cnt += fre * marks[i];
  }
  cout << cnt << '\n';
}
int main() {
  long long TESTS = 1;
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  while (TESTS--) solve();
  return 0;
}
