#include <bits/stdc++.h>
using namespace std;
void File() {
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
}
int countDivisors(long long n) {
  int cnt = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else
        cnt += 2;
    }
  }
  return cnt;
}
int const N = 6e3 + 9, MOD = 1e9 + 7, oo = 1e9 + 7;
vector<vector<int>> v(N);
int vis[N];
int col[N];
map<int, int> mm;
char arr[N][N];
int c[N];
int main() {
  long long n, m, i, j, s = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < int(m); i++) cin >> c[i];
  int mini = 0;
  for (j = 0; j < m; j++) {
    mm.clear();
    mini = 0;
    for (i = 0; i < n; i++) {
      mm[arr[i][j]]++;
      mini = max(mini, mm[arr[i][j]]);
    }
    s += mini * c[j];
  }
  cout << s;
  return 0;
}
