#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int dp[1 << 20], a[22][22], c[22][22], f[22][22];
char s[22][22];
int main() {
  int T, i, j, k, m, n;
  scanf("%d%d", &n, &m);
  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++) {
      int mx = 0;
      for (k = 0; k < n; k++) {
        if (s[k][j] == s[i][j]) {
          f[i][j] |= (1 << k);
          c[i][j] += a[k][j];
          mx = max(mx, a[k][j]);
        }
      }
      c[i][j] -= mx;
    }
  memset(dp, 63, sizeof(dp));
  dp[0] = 0;
  for (i = 1; i < 1 << n; i++) {
    for (j = 0; j < n; j++)
      if (i >> j & 1) break;
    for (k = 0; k < m; k++) {
      dp[i] = min(dp[i], dp[i ^ (1 << j)] + a[j][k]);
      dp[i] = min(dp[i], dp[i & (i ^ f[j][k])] + c[j][k]);
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
