#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[22][22];
int cost[22][22];
int rev_st[22][22];
int rev_ct[22][22];
int dp[1 << 20];
int main() {
  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]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      int mx = 0;
      for (int k = 0; k < n; ++k)
        if (str[i][j] == str[k][j]) {
          rev_st[i][j] |= (1 << k);
          rev_ct[i][j] += cost[k][j];
          mx = max(mx, cost[k][j]);
        }
      rev_ct[i][j] -= mx;
    }
  memset(dp, 63, sizeof(dp));
  dp[0] = 0;
  for (int st = 1; st < (1 << n); ++st) {
    int t = 0;
    for (int i = 0; i < n; ++i)
      if (st >> i & 1) t = i;
    for (int j = 0; j < m; ++j) {
      dp[st] = min(dp[st], dp[st ^ (1 << t)] + cost[t][j]);
      dp[st] = min(dp[st], dp[st & (st ^ rev_st[t][j])] + rev_ct[t][j]);
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
}
