#include <bits/stdc++.h>
using namespace std;
char str[110][110];
int num[110][110], sta[110][110], sum[110][110], f[2000010], n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &num[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int mx = 0;
      for (int k = 1; k <= n; k++)
        if (str[i][j] == str[k][j])
          sta[i][j] |= 1 << (k - 1), mx = max(mx, num[k][j]),
                                     sum[i][j] += num[k][j];
      sum[i][j] -= mx;
    }
  for (int i = 1; i < (1 << n); i++) f[i] = 1000000000;
  for (int i = 0; i < (1 << n); i++)
    for (int j = 1; j <= n; j++)
      if (!((i >> (j - 1)) & 1))
        for (int k = 1; k <= m; k++) {
          f[i | (1 << (j - 1))] = min(f[i | (1 << (j - 1))], f[i] + num[j][k]);
          f[i | sta[j][k]] = min(f[i | sta[j][k]], f[i] + sum[j][k]);
        }
  printf("%d\n", f[(1 << n) - 1]);
}
