#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string str[n];
  for (int i = 0; i < n; i++) cin >> str[i];
  int brr[m];
  for (int i = 0; i < m; i++) cin >> brr[i];
  int count = 0;
  for (int i = 0; i < m; i++) {
    int arr[5] = {0};
    for (int j = 0; j < n; j++) {
      arr[str[j][i] - 'A']++;
    }
    int k = *max_element(arr, arr + 5);
    count += k * brr[i];
  }
  cout << count;
}
