#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
char s[30][30];
int a[30][30], b[30][30], c[30][30], pw[30] = {1}, d[30][30], e[(1 << 20) + 10],
                                     n, m;
int main() {
  int i, j, k, x, y, z;
  for (i = 1; i < 26; i++) pw[i] = pw[i - 1] << 1;
  scanf("%d %d", &n, &m);
  for (i = 1; i < pw[n]; i++) e[i] = inf;
  e[0] = 0;
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) s[i][j] -= 'a';
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      b[j][s[i][j]] += a[i][j];
      d[j][s[i][j]] += pw[i];
      c[j][s[i][j]] = max(c[j][s[i][j]], a[i][j]);
    }
  for (i = 0; i < m; i++)
    for (j = 0; j < 26; j++) b[i][j] -= c[i][j];
  for (i = 1; i < pw[n]; i++) {
    k = i & -i;
    x = 31 - __builtin_clz(k);
    for (j = 0; j < m; j++) {
      e[i] = min(e[i], a[x][j] + e[i - k]);
      z = b[j][s[x][j]] + e[i ^ (i & d[j][s[x][j]])];
      e[i] = min(e[i], z);
    }
  }
  printf("%d\n", e[i - 1]);
}
