#include <bits/stdc++.h>
template <class T>
std::vector<T> read(int n) {
  std::vector<T> res(n);
  for (auto& r : res) {
    std::cin >> r;
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
  int n, m;
  std::cin >> n >> m;
  std::vector<std::map<char, int>> freq(m);
  for (int i = 0; i < n; i++) {
    std::string s;
    std::cin >> s;
    for (int j = 0; j < m; j++) {
      freq[j][s[j]]++;
    }
  }
  auto a = read<int>(m);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int hi = 0, tot = 0;
    for (char j = 'A'; j <= 'E'; j++) {
      hi = std::max(hi, freq[i][j]);
      tot += freq[i][j];
    }
    assert(tot == n);
    ans += hi * a[i];
  }
  std::cout << ans << '\n';
}
