#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int p[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int score = 0;
  for (int i = 0; i < m; i++) {
    map<char, int> hm;
    for (int j = 0; j < n; j++) {
      hm[a[j][i]]++;
    }
    int y = 0;
    for (auto x : hm) {
      if (y < x.second) {
        y = x.second;
      }
    }
    score += y * p[i];
  }
  cout << score << endl;
}
