#include <bits/stdc++.h>
using namespace std;
int N, M, cost[20][20], dp[1 << 20];
char sd[20][21];
int sv(int bs) {
  int& ans = dp[bs];
  if (ans == -1) {
    ans = INT_MAX;
    int n = __builtin_ffs(bs) - 1;
    for (int m = 0; m < int(M); m++) {
      int nbs = bs & ~(1 << n);
      ans = min(ans, cost[n][m] + sv(nbs));
      int rc = 0, mc = 0;
      for (int n2 = 0; n2 < int(N); n2++)
        if (sd[n2][m] == sd[n][m]) {
          rc += cost[n2][m];
          nbs &= ~(1 << n2);
          mc = max(mc, cost[n2][m]);
        }
      ans = min(ans, rc - mc + sv(nbs));
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &N, &M);
  for (int n = 0; n < int(N); n++) scanf("%s", sd[n]);
  for (int n = 0; n < int(N); n++)
    for (int m = 0; m < int(M); m++) scanf("%d", &cost[n][m]);
  memset(dp, -1, sizeof dp);
  dp[0] = 0;
  printf("%d\n", sv((1 << N) - 1));
}
