#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  vector<string> str(n);
  vector<long long> v(m);
  for (long long i = 0; i < n; i++) {
    cin >> str[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> v[i];
  }
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    map<char, long long> make_pair;
    for (long long j = 0; j < n; j++) {
      make_pair[str[j][i]]++;
    }
    long long maxx = -1;
    for (auto k : make_pair) {
      maxx = max(maxx, k.second);
    }
    ans += maxx * v[i];
  }
  cout << ans;
}
