#include <bits/stdc++.h>
using namespace std;
char s[25][25];
int a[25][25], n, m, sum[25][25], val[25][25];
int dp[1 << 21];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int sm = 0, tmp = -INT_MAX;
      for (int k = 1; k <= n; k++)
        if (s[k][j] == s[i][j]) {
          sm += a[k][j];
          tmp = max(tmp, a[k][j]);
          sum[i][j] |= (1 << k - 1);
        }
      val[i][j] = sm - tmp;
    }
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  for (int i = 0, j; i < (1 << n) - 1; i++) {
    for (j = 0; j < n; j++)
      if (!(i & (1 << j))) break;
    for (int k = 0; k < m; k++)
      dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + a[j + 1][k + 1]),
                   dp[i | sum[j + 1][k + 1]] = min(dp[i | sum[j + 1][k + 1]],
                                                   dp[i] + val[j + 1][k + 1]);
  }
  return printf("%d\n", dp[(1 << n) - 1]), 0;
}
