#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, q;
int f[1100000], a[22][22], t[22][22], w[22][22];
char s[22][22];
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("\n%s", s[i]);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      q = 0;
      for (k = 1; k <= n; ++k)
        if (s[k][j - 1] == s[i][j - 1]) {
          t[i][j] += (1 << (k - 1));
          w[i][j] += a[k][j];
          q = max(q, a[k][j]);
        }
      w[i][j] -= q;
    }
  for (k = 1; k < (1 << n); ++k) f[k] = 1e9;
  for (k = 0; k + 1 < (1 << n); ++k) {
    for (j = 1; j <= n; ++j)
      if (((k >> (j - 1)) & 1) == 0) {
        i = j;
        break;
      }
    for (j = 1; j <= m; ++j) {
      f[(k | (1 << (i - 1)))] = min(f[(k | (1 << (i - 1)))], f[k] + a[i][j]);
      f[(k | t[i][j])] = min(f[(k | t[i][j])], f[k] + w[i][j]);
    }
  }
  printf("%d", f[(1 << n) - 1]);
}
