#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int d[1100010], v[25][25], sum[25][25], poz[25][25];
char sir[25][25];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("\n%s", sir[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &v[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      poz[i][j] = 1 << (i - 1);
      for (int q = 1; q <= n; q++)
        if (sir[q][j] == sir[i][j] && q != i) {
          sum[i][j] += v[q][j];
          poz[i][j] += 1 << (q - 1);
        }
    }
  int lim = 1 << n;
  for (int i = 1; i < lim; i++) {
    d[i] = inf;
    for (int j = 0; j < n; j++)
      if (i & (1 << j))
        for (int q = 1; q <= m; q++) {
          d[i] = min(d[i], v[j + 1][q] + d[i ^ (1 << j)]);
          d[i] = min(d[i], sum[j + 1][q] + d[i ^ (i & poz[j + 1][q])]);
        }
  }
  printf("%d", d[lim - 1]);
  return 0;
}
