#include <bits/stdc++.h>
using std::max;
using std::min;
using std::sort;
const int maxn = 27;
const int maxs = (1 << 20) + 7;
int a[maxn][maxn];
char s[maxn][maxn];
int f[maxs], lg[maxs], val[maxn][maxs];
int st[maxn][maxn];
int N, M;
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]);
  int all = (1 << N) - 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      for (int k = 1; k <= N; k++)
        if (s[k][j] == s[i][j]) st[i][j] |= 1 << k - 1;
  memset(f, 0x3f, sizeof(f));
  f[0] = 0;
  for (int i = 1; i <= N; i++) lg[1 << i - 1] = i;
  for (int i = 1; i <= M; i++)
    for (int k = 1; k <= all; k++)
      val[i][k] = val[i][k & (k - 1)] + a[lg[k & -k]][i];
  for (int i = 0; i <= all; i++) {
    for (int j = 1; j <= N; j++)
      if (~i & (1 << j - 1)) {
        for (int k = 1; k <= M; k++)
          f[i | st[j][k]] =
              min(f[i | st[j][k]], f[i] + val[k][st[j][k] ^ (1 << j - 1)]),
                f[i | (1 << j - 1)] = min(f[i | (1 << j - 1)], f[i] + a[j][k]);
      }
  }
  printf("%d\n", f[all]);
  return 0;
}
