#include <bits/stdc++.h>
using namespace std;
long long int max(long long int x, long long int y) {
  if (x > y) return x;
  return y;
}
long long int min(long long int x, long long int y) {
  if (x < y) return x;
  return y;
}
long long int getSum(long long int n) {
  int sum;
  for (sum = 0; n > 0; sum += n % 10, n /= 10)
    ;
  return sum;
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int two(long long int a, long long int b, long long int c) {
  long long int temp = 0;
  if (a % 2 == 1) temp++;
  if (b % 2 == 1) temp++;
  if (c % 2 == 1) temp++;
  if (temp == 2)
    return true;
  else
    return false;
}
int CF(const vector<int> &p) {
  int ans = 0;
  for (int i = 0; i < p.size(); i++)
    if (p[i] > 1) ans += p[i];
  return ans;
}
long long int res = 1;
long long int power(long long int y) {
  if (y == 0) return 1;
  res *= 2;
  res %= 1000000007;
  return res;
}
void fib(long long int n) {
  int a = 0, b = 1, temp;
  bool flag = true;
  cout << "0 ";
  while (true) {
    temp = a + b;
    if (temp == n) flag = false;
    if (flag == false)
      break;
    else
      a = b, b = temp;
  }
  cout << a << " " << b;
}
long long int pF(int n) {
  long long int count = 0;
  for (int i = 2; i <= n / 2; i++) {
    if (n % i == 0 && isPrime(i)) count++;
  }
  return count;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int test = 1;
  while (test--) {
    long long int n, m;
    cin >> n >> m;
    string s[n];
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    for (int i = 0; i < n; i++) cin >> s[i];
    long long int count = 0;
    for (int i = 0; i < m; i++) {
      map<long long int, long long int> ma;
      long long int temp;
      cin >> temp;
      for (int j = 0; j < n; j++) ma[s[j][i] - 'A']++;
      long long int mo = 0;
      for (int j = 0; j < ma.size(); j++) mo = max(ma[j], mo);
      count += temp * mo;
    }
    cout << count;
  }
  return 0;
}
