#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 10;
char str[20][21];
int a[20][20], ch[20][20], same[20][20], f[1 << 20];
int main() {
  int n, m, i, j, k, pos, v, tot_n;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", str[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++) {
      v = 0;
      for (k = 0; k < n; k++)
        if (str[i][j] == str[k][j]) {
          same[i][j] |= 1 << k;
          ch[i][j] += a[k][j];
          v = max(v, a[k][j]);
        }
      ch[i][j] -= v;
    }
  memset(f, 0x7f, sizeof(f));
  f[0] = 0;
  tot_n = 1 << n;
  for (i = 1; i < tot_n; i++) {
    for (pos = 0; pos < n; pos++)
      if (i & 1 << pos) break;
    for (j = 0; j < m; j++) {
      f[i] = min(f[i], f[i & (i ^ same[pos][j])] + ch[pos][j]);
      f[i] = min(f[i], f[i ^ 1 << pos] + a[pos][j]);
    }
  }
  printf("%d", f[tot_n - 1]);
  return 0;
}
