#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  x = f ? -x : x;
}
inline void readChar(char &c) {
  for (c = getchar(); c < 'A' || c > 'E'; c = getchar())
    ;
}
template <class T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  T y = 1;
  int len = 1;
  for (; y <= x / 10; y *= 10) ++len;
  for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
const int MAXN = 1e3;
int n, m, ans, a[MAXN + 5];
char s[MAXN + 5][MAXN + 5];
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) readChar(s[i][j]);
  for (int i = 1; i <= m; ++i) read(a[i]);
  for (int i = 1; i <= m; ++i) {
    int maxn = 0, tot[5] = {0};
    for (int j = 1; j <= n; ++j) {
      ++tot[(int)s[j][i] - 'A'];
      maxn = max(maxn, tot[(int)s[j][i] - 'A']);
    }
    ans += maxn * a[i];
  }
  write(ans);
  putchar('\n');
  return 0;
}
