#include <bits/stdc++.h>
using namespace std;
char str[25][25];
int cost[25][25];
const int maxc = 1 << 20;
int dp[maxc];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", str + i);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) scanf("%d", &cost[i][j]);
  }
  int total = (1 << n) - 1;
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i < total; i++) {
    if (dp[i] == -1) continue;
    int j = 0;
    while (((i >> j) & 1) == 1) j++;
    for (int k = 0; k < m; k++) {
      int cnt = 0, sumc = 0, maxc = 0, tmp = 0;
      for (int z = 0; z < n; z++) {
        if (str[z][k] == str[j][k]) {
          cnt++;
          sumc += cost[z][k];
          maxc = max(maxc, cost[z][k]);
          tmp |= (1 << z);
        }
      }
      if (cnt == 1) {
        if (dp[i | (1 << j)] == -1)
          dp[i | (1 << j)] = dp[i];
        else
          dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i]);
      } else {
        if (dp[i | (1 << j)] == -1)
          dp[i | (1 << j)] = dp[i] + cost[j][k];
        else
          dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + cost[j][k]);
        if (dp[i | tmp] == -1)
          dp[i | tmp] = dp[i] + sumc - maxc;
        else
          dp[i | tmp] = min(dp[i | tmp], dp[i] + sumc - maxc);
      }
    }
  }
  printf("%d\n", dp[total]);
  return 0;
}
