#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  unordered_map<char, int> mp;
  cin >> n >> m;
  string s[n];
  long long b[m], y = 0, i, j, a, maxx = 0;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < m; i++) {
    mp.clear();
    for (j = 0; j < n; j++) mp[s[j][i]]++;
    maxx = 0;
    for (auto p : mp)
      if (p.second > maxx) maxx = p.second;
    b[i] = maxx;
  }
  for (i = 0; i < m; i++) {
    cin >> a;
    y += (b[i] * a);
  }
  cout << y;
}
