#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  unsigned long int total = 0;
  string current;
  int current_max;
  int score;
  cin >> n >> m;
  int a[1000] = {0};
  int b[1000] = {0};
  int c[1000] = {0};
  int d[1000] = {0};
  int e[1000] = {0};
  for (int i = 0; i < n; i++) {
    cin >> current;
    for (int j = 0; j < m; j++) {
      if (current[j] == 'A') a[j] += 1;
      if (current[j] == 'B') b[j] += 1;
      if (current[j] == 'C') c[j] += 1;
      if (current[j] == 'D') d[j] += 1;
      if (current[j] == 'E') e[j] += 1;
    }
  }
  for (int i = 0; i < m; i++) {
    current_max = 0;
    if (a[i] > current_max) current_max = a[i];
    if (b[i] > current_max) current_max = b[i];
    if (c[i] > current_max) current_max = c[i];
    if (d[i] > current_max) current_max = d[i];
    if (e[i] > current_max) current_max = e[i];
    cin >> score;
    total += current_max * score;
  }
  cout << total;
  return 0;
}
