#include <bits/stdc++.h>
using namespace std;
const int OO = int(1e6);
bool dcmp(double a, double b) { return fabs(a - b) < 1e-8; }
int Dcmp(long double a, long double b) {
  return fabs(a - b) <= 1e-8 ? 0 : a < b ? -1 : 1;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void INPUT() {
  cout << fixed << setprecision(13);
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
int main() {
  INPUT();
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  string answers[n];
  int grades[m];
  for (int i = 0; i < (int)(n); ++i) cin >> answers[i];
  for (int i = 0; i < (int)(m); ++i) cin >> grades[i];
  int Most[30];
  for (int i = 0; i < m; i++) {
    memset(Most, 0, sizeof(Most));
    for (int j = 0; j < n; ++j) {
      char let = answers[j][i];
      Most[let - 65]++;
    }
    int mx = 0;
    for (int k = 0; k < 30; k++) {
      mx = max(mx, Most[k]);
    }
    ans += grades[i] * mx;
  }
  cout << ans << '\n';
  return 0;
}
