#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  int n, m;
  char x;
  cin >> n >> m;
  int arr[m][5];
  memset(arr, 0, sizeof(arr));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      arr[j][x - 'A'] += 1;
    }
  }
  int maxi;
  int y;
  int class_p = 0;
  for (int k = 0; k < m; ++k) {
    maxi = 0;
    for (int i = 0; i < 5; ++i) {
      maxi = max(maxi, arr[k][i]);
    }
    cin >> y;
    class_p += maxi * y;
  }
  cout << class_p << "\n";
  return 0;
}
