#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5, maxl = 30, maxm = 1 << 21, oo = 1e9;
char s[maxl][maxl];
int f[maxm];
int a[maxl][maxl];
int w[maxl][maxl];
int num[maxl][maxl];
int d[maxl];
int n, m, i, j, k, M, u;
int main() {
  scanf("%d%d", &n, &m);
  d[0] = 1;
  for (i = 1; i <= 25; i++) d[i] = d[i - 1] << 1;
  for (i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      int &sum = w[i][j], &N = num[i][j], Max = 0;
      N |= d[i - 1];
      for (k = 1; k <= n; k++)
        if (s[i][j] == s[k][j]) {
          Max = max(Max, a[k][j]);
          sum += a[k][j];
          N |= d[k - 1];
        }
      sum -= Max;
    }
  M = 1 << n;
  for (i = 1; i < M; i++) f[i] = oo;
  for (u = 0; u < M; u++) {
    int l = 0;
    for (i = 1; i <= n; i++)
      if (!(d[i - 1] & u)) {
        l = i;
        break;
      }
    for (i = 1; i <= m; i++)
      f[u + d[l - 1]] = min(f[u + d[l - 1]], f[u] + a[l][i]);
    for (i = 1; i <= m; i++) {
      int nex = u | num[l][i];
      f[nex] = min(f[nex], f[u] + w[l][i]);
    }
  }
  printf("%d", f[M - 1]);
  return 0;
}
