#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vint = vector<int>;
class solver {
 private:
 public:
  void solve(int n) {
    int m;
    cin >> m;
    vector<string> vec(n);
    for (int i = 0; i < n; i++) {
      cin >> vec[i];
    }
    vector<int> cnts(m);
    for (int i = 0; i < m; i++) {
      map<char, int> mp;
      for (int z = 0; z < n; z++) {
        mp[vec[z][i]]++;
      }
      for (auto it : mp) {
        cnts[i] = max(cnts[i], it.second);
      }
    }
    int ans = 0;
    vector<int> points(m);
    int pos = 0;
    for (auto &it : points) {
      cin >> it;
      ans += it * cnts[pos];
      pos++;
    }
    cout << ans << endl;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) {
    solver s;
    s.solve(n);
  }
}
