#include <bits/stdc++.h>
using namespace std;
char s[30][30];
int data[30][30], common[30][30], b[30][30], dp[1 << 22], n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 0; i < n; i++) scanf("%s", s[i]);
  for (register int i = 0; i < n; i++)
    for (register int j = 0; j < m; j++) scanf("%d", &data[i][j]);
  for (register int i = 0; i < n; i++)
    for (register int j = 0; j < m; j++) {
      int sum = 0, x = -1 << 22;
      for (register int k = 0; k < n; k++)
        if (s[k][j] == s[i][j]) {
          sum += data[k][j], x = max(x, data[k][j]);
          common[i][j] |= (1 << k);
        }
      b[i][j] = sum - x;
    }
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  int maxsit = (1 << n);
  for (register int i = 0; i < maxsit; i++)
    for (register int j = 0; j < n; j++)
      if ((i & (1 << j)) == 0)
        for (register int k = 0; k < m; k++) {
          dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + data[j][k]);
          dp[i | common[j][k]] = min(dp[i | common[j][k]], dp[i] + b[j][k]);
        }
  printf("%d\n", dp[maxsit - 1]);
  return 0;
}
