#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
using namespace std;
template <class T, class U>
inline void checkmin(T& x, U y) {
  if (y < x) x = y;
}
template <class T, class U>
inline void checkmax(T& x, U y) {
  if (y > x) x = y;
}
template <class T, class U>
inline bool ifmax(T& x, U y) {
  if (y > x) return x = y, true;
  return false;
}
template <class T, class U>
inline bool ifmin(T& x, U y) {
  if (y < x) return x = y, true;
  return false;
}
template <class T>
inline void sort(T& a) {
  sort(a.begin(), a.end());
}
template <class T>
inline void rsort(T& a) {
  sort(a.rbegin(), a.rend());
}
template <class T>
inline void reverse(T& a) {
  reverse(a.begin(), a.end());
}
template <class T, class U>
inline istream& operator>>(istream& str, pair<T, U>& p) {
  return str >> p.first >> p.second;
}
template <class T>
inline istream& operator>>(istream& str, vector<T>& a) {
  for (auto& i : a) str >> i;
  return str;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12);
  srand(94385);
  long long n, m;
  cin >> n >> m;
  vector<vector<int>> a;
  vector<int> b(5);
  vector<long long> c(m);
  a.assign(n, vector<int>(m));
  for (int i = 0; i < n; ++i) {
    char second[1001];
    cin >> second;
    for (int j = 0; j < strlen(second); ++j) {
      if (second[j] == 'B')
        a[i][j] = 1;
      else if (second[j] == 'C')
        a[i][j] = 2;
      else if (second[j] == 'D')
        a[i][j] = 3;
      else if (second[j] == 'E')
        a[i][j] = 4;
    }
  }
  for (int i = 0; i < m; ++i) cin >> c[i];
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i) {
      b[a[i][j]]++;
    }
    long long k = 0;
    for (int i = 0; i < 5; ++i) {
      if (k < b[i]) k = b[i];
    }
    a[0][j] = k * c[j];
    for (int i = 0; i < 5; ++i) {
      b[i] = 0;
    }
  }
  long long ans = 0;
  for (int j = 0; j < m; ++j) ans += a[0][j];
  cout << ans;
  return 0;
}
