#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[25][25];
int a[25][25], sum[25][25], l[25][25];
int f[2000001];
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]);
  memset(f, 0x7f, sizeof(f));
  f[0] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int sumx = 0, lx = 0, max0 = 0;
      for (int k = 1; k <= n; k++)
        if (s[k][j] == s[i][j]) {
          sumx += a[k][j];
          max0 = max(max0, a[k][j]);
          lx |= (1 << (k - 1));
        }
      sum[i][j] = sumx - max0;
      l[i][j] = lx;
    }
  for (int i = 0; i <= (1 << n) - 2; i++) {
    if (f[i] > 1e9) continue;
    int k;
    for (int j = 0; j < n; j++)
      if (((1 << j) & i) == 0) {
        k = j + 1;
        break;
      }
    for (int j = 1; j <= m; j++) {
      f[i | (1 << (k - 1))] = min(f[i | (1 << (k - 1))], f[i] + a[k][j]);
      f[i | l[k][j]] = min(f[i | l[k][j]], f[i] + sum[k][j]);
    }
  }
  printf("%d\n", f[(1 << n) - 1]);
  return 0;
}
