#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long MOD1 = 998244353;
const long long MIN_LL = -1e18;
const long long MAX_LL = 1e18;
const int MAX_INT = 1e9;
const int MIN_INT = -1e9;
const long double pie = 3.1415926535;
long long fpow(long long n, long long p) {
  ;
  long long m = 1;
  while (p) {
    if (p % 2) m *= n;
    p >>= 1;
    n *= n;
  }
  return m;
}
long long mfpow(long long n, long long p, long long M) {
  long long m = 1;
  n %= M;
  while (p) {
    if (p % 2) m = (m * n) % M;
    n = (n * n) % M;
    p >>= 1;
  }
  return m % M;
}
long long invmod(long long n, long long m) { return mfpow(n, m - 2, m); }
const vector<long long> days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool br, br1, br2;
char ch, ch1, ch2;
long long n, m, k, x, y, z, d, mini, maxi, l, r, sum, t, w, h;
pair<long long, long long> p, p1, p2;
string s, s1, s2, s3;
multiset<long long> mst;
set<long long> st, st1, st2, st3;
map<long long, long long> mp, mp1, mp2;
long long a[(int)1e6 + 100];
void solve() {
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) {
    mp.clear();
    for (int j = 0; j < n; j++) mp[s[j][i]]++;
    a[i] = 0;
    for (auto j : mp)
      if (a[i] < j.second) a[i] = j.second;
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    sum += x * a[i];
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
