#include <bits/stdc++.h>
const int MAX = 1 << 21;
const int MAX_V = 1e3 + 5;
const int INF = 1e9 + 5;
const long long INF2 = 4e18 + 5;
const double M = 4e18;
using namespace std;
const int MOD = 1e9 + 7;
const double eps = 0.000000001;
int n, m;
int dp[MAX], cost[25][25], Max;
int col[25][25], st[25][25];
char a[25][25];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", a[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++) {
      Max = 0;
      for (int s = 0; s < n; s++) {
        if (a[i][j] == a[s][j]) {
          Max = max(Max, cost[s][j]);
          col[i][j] += cost[s][j];
          st[i][j] |= (1 << s);
        }
      }
      col[i][j] -= Max;
    }
  }
  Max = (1 << n) - 1;
  fill(dp, dp + (1 << n), INF);
  dp[0] = 0;
  for (int i = 0; i < Max; i++) {
    for (int j = 0; j < n; ++j) {
      if (!((i >> j) & 1)) {
        int now = 1 << j;
        for (int s = 0; s < m; s++) {
          dp[i | now] = min(dp[i | now], dp[i] + cost[j][s]);
          dp[i | st[j][s]] = min(dp[i | st[j][s]], dp[i] + col[j][s]);
        }
      }
    }
  }
  printf("%d\n", dp[Max]);
  return 0;
}
