#include <bits/stdc++.h>
using namespace std;
const int MAXN = 21;
int n, m, ii, h, i, j, jj, mk, tot, mx;
int addMask[MAXN][MAXN], cost[MAXN][MAXN], addCost[MAXN][MAXN];
int dp[(1 << (MAXN + 1))];
char s[MAXN][MAXN];
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &cost[i][j]);
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      mk = tot = mx = 0;
      for (ii = 1; ii <= n; ii++) {
        if (s[i][j] == s[ii][j]) {
          mk |= (1 << (ii - 1));
          tot += cost[ii][j];
          mx = max(mx, cost[ii][j]);
        }
      }
      addMask[i][j] = mk;
      addCost[i][j] = tot - mx;
    }
  }
  h = (1 << n) - 1;
  for (i = 0; i <= h; i++) {
    dp[i] = (int)1e9;
  }
  dp[0] = 0;
  for (i = 0; i < h; i++) {
    for (j = 1; (i & (1 << (j - 1))); j++)
      ;
    for (jj = 1; jj <= m; jj++) {
      dp[i ^ (1 << (j - 1))] = min(dp[i ^ (1 << (j - 1))], dp[i] + cost[j][jj]);
      dp[i | addMask[j][jj]] =
          min(dp[i | addMask[j][jj]], dp[i] + addCost[j][jj]);
    }
  }
  printf("%d\n", dp[h]);
  return 0;
}
