#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  char arr[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  }
  int arr1[m];
  for (int i = 0; i < m; i++) cin >> arr1[i];
  int sum = 0;
  for (int j = 0; j < m; j++) {
    int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0, cnt5 = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i][j] == 'A')
        cnt1++;
      else if (arr[i][j] == 'B')
        cnt2++;
      else if (arr[i][j] == 'C')
        cnt3++;
      else if (arr[i][j] == 'D')
        cnt4++;
      else
        cnt5++;
    }
    sum += arr1[j] * max(max(max(cnt1, cnt2), max(cnt3, cnt4)), cnt5);
  }
  cout << sum;
  return 0;
}
