#include <bits/stdc++.h>
using namespace std;
char s[20][20];
int c[20][20];
int dp[1 << 20];
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", &c[i][j]);
  }
  memset(dp, 0x3f, sizeof dp);
  dp[0] = 0;
  for (int i = 0; i + 1 < 1 << n; i++) {
    if (dp[i] == 0x3f3f3f3f) continue;
    int r;
    for (r = 0; r < n; r++) {
      if (!(((i) >> (r)) & 1)) break;
    }
    int id = i | (1 << r);
    for (int j = 0; j < m; j++) {
      dp[id] = min(dp[id], dp[i] + c[r][j]);
      int jd = i, v = 0, mx = 0;
      for (int k = 0; k < n; k++) {
        if (s[k][j] == s[r][j]) {
          v += c[k][j];
          jd |= (1 << k);
          mx = max(mx, c[k][j]);
        }
      }
      dp[jd] = min(dp[jd], dp[i] + v - mx);
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
}
