#include <bits/stdc++.h>
using namespace std;
const int maxn = 20 + 1;
const int maxm = 20 + 1;
const int INF = (1 << 30);
int cost[maxn][maxm], dp[(1 << maxn)], same[maxn][maxm], most[maxn][maxm],
    mostcost[maxn][maxm];
char s[maxn][maxm];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[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++) {
      for (int k = 0; k < n; k++)
        if (s[i][j] == s[k][j]) {
          same[i][j] |= (1 << k);
          most[i][j] = max(most[i][j], cost[k][j]);
          mostcost[i][j] += cost[k][j];
        }
      mostcost[i][j] -= most[i][j];
    }
  for (int S = (1 << n) - 1; S >= 0; S--) dp[S] = INF;
  dp[(1 << n) - 1] = 0;
  for (int S = (1 << n) - 1; S >= 0; S--) {
    for (int i = 0; i < n; i++) {
      if (!(S & (1 << i))) continue;
      for (int j = 0; j < m; j++) {
        dp[S ^ (1 << i)] = min(dp[S ^ (1 << i)], dp[S] + cost[i][j]);
        dp[S ^ (S & same[i][j])] =
            min(dp[S ^ (S & same[i][j])], dp[S] + mostcost[i][j]);
      }
      break;
    }
  }
  printf("%d\n", dp[0]);
}
