#include <bits/stdc++.h>
using namespace std;
inline void ckmax(int &a, int b) { a = max(a, b); }
inline void ckmin(int &a, int b) { a = min(a, b); }
inline int read() {
  int num = 0, flag = 1;
  char c = ' ';
  for (; c > '9' || c < '0'; c = getchar())
    if (c == '-') flag = -1;
  for (; c >= '0' && c <= '9';
       num = (num << 1) + (num << 3) + c - 48, c = getchar())
    ;
  return num * flag;
}
string s[22];
int a[22][22], n, m, qwq[22][22], b[22][22];
int dp[1 << 22];
signed main() {
  n = read(), m = read();
  for (register int i = (0); i <= (n - 1); i++) cin >> s[i];
  for (register int i = (0); i <= (n - 1); i++)
    for (register int j = (0); j <= (m - 1); j++) a[i][j] = read();
  for (register int i = (0); i <= (n - 1); i++) {
    for (register int j = (0); j <= (m - 1); j++) {
      int sum = 0, val = -(1 << 30);
      for (register int k = (0); k <= (n - 1); k++) {
        if (s[k][j] == s[i][j]) {
          sum += a[k][j], ckmax(val, a[k][j]);
          qwq[i][j] |= (1 << k);
        }
      }
      b[i][j] = sum - val;
    }
  }
  memset(dp, 127 / 2, sizeof(dp));
  dp[0] = 0;
  for (register int i = (0); i <= ((1 << n) - 1); i++) {
    for (register int j = (0); j <= (n - 1); j++) {
      if (!(i & (1 << j))) {
        for (register int k = (0); k <= (m - 1); k++) {
          ckmin(dp[i | (1 << j)], dp[i] + a[j][k]);
          ckmin(dp[i | qwq[j][k]], dp[i] + b[j][k]);
        }
      }
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
