#include <bits/stdc++.h>
using namespace std;
char s[21][21];
int cost[21][21];
int dp[1 << 21];
int xh[21][21][2];
int change[21][21][2];
bool fh[21];
const int INF = 0x3f3f3f3f;
int main() {
  int n, m;
  int begin = 0;
  scanf("%d%d", &n, &m);
  memset(dp, 0x3f, sizeof(dp));
  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++) {
    bool flag = false;
    for (int j = 0; j < m && !flag; j++) {
      bool flag1 = true;
      for (int k = 0; k < n && flag1; k++) {
        if (j == k) continue;
        if (s[i][j] == s[k][j]) flag1 = false;
      }
      if (flag1) flag = true;
    }
    if (flag) fh[i] = true;
  }
  for (int i = 0; i < n; i++) {
    if (fh[i]) continue;
    for (int j = 0; j < m; j++) {
      int cnt = 0;
      for (int k = 0; k < n; k++) {
        if (k == i) continue;
        if (s[i][j] == s[k][j]) {
          change[i][j][1] = change[i][j][1] | (1 << k);
          cnt++;
          xh[i][j][1] += cost[k][j];
        }
      }
      if (cnt == 1)
        change[i][j][0] = change[i][j][1];
      else
        change[i][j][0] = 0;
      xh[i][j][0] = cost[i][j];
    }
  }
  for (int i = 0; i < n; i++)
    if (fh[i]) begin = begin | (1 << i);
  dp[begin] = 0;
  for (int i = begin; i < (1 << n); i++)
    if (dp[i] != INF)
      for (int j = 0; j < n; j++)
        if (!((1 << j) & i)) {
          for (int k = 0; k < m; k++) {
            for (int t = 0; t < 2; t++) {
              int next = i | (1 << j);
              next = next | change[j][k][t];
              dp[next] = min(dp[next], dp[i] + xh[j][k][t]);
            }
          }
        }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
