#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m, val[25][25], dp[1 << 21];
char mp[25][25];
int main() {
  memset(dp, INF, sizeof(dp));
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mp[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &val[i][j]);
    }
  }
  dp[0] = 0;
  for (int i = 0; i < (1 << n); i++) {
    for (int j = 1; j <= n; j++) {
      if (!(i & (1 << (j - 1)))) {
        for (int k = 1; k <= m; k++) {
          dp[i | (1 << (j - 1))] =
              min(dp[i | (1 << (j - 1))], dp[i] + val[j][k]);
          int sum = 0, maxv = 0, cnt = 0;
          for (int r = 1; r <= n; r++) {
            if (mp[r][k] == mp[j][k]) {
              sum += val[r][k];
              cnt = cnt | (1 << (r - 1));
              maxv = max(maxv, val[r][k]);
            }
          }
          dp[cnt | i] = min(dp[cnt | i], dp[i] + sum - maxv);
        }
        break;
      }
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
