#include <bits/stdc++.h>
const int oo = 1e9;
int n, m, cost[22][22], cb[22][22], cc[22][22], d[1 << 20], lb;
char String[22][22];
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", String[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 k = 0; k < m; k++) {
      int Max = 0;
      for (int j = 0; j < n; j++) {
        if (String[i][k] == String[j][k]) {
          cb[i][k] |= (1 << j);
          cc[i][k] += cost[j][k];
          if (cost[j][k] > Max) Max = cost[j][k];
        }
      }
      cc[i][k] -= Max;
    }
  }
  for (int i = 0; i < (1 << n); i++) d[i] = oo;
  d[0] = 0;
  for (int i = 1; i < (1 << n); i++) {
    for (int j = 0; j < n; j++)
      if ((i >> j) & 1) {
        lb = j;
        break;
      }
    for (int j = 0; j < m; j++)
      d[i] = ((((d[i]) > (d[i & (i ^ cb[lb][j])] + cc[lb][j])
                    ? (d[i & (i ^ cb[lb][j])] + cc[lb][j])
                    : (d[i]))) > (d[i ^ (1 << lb)] + cost[lb][j])
                  ? (d[i ^ (1 << lb)] + cost[lb][j])
                  : (((d[i]) > (d[i & (i ^ cb[lb][j])] + cc[lb][j])
                          ? (d[i & (i ^ cb[lb][j])] + cc[lb][j])
                          : (d[i]))));
  }
  printf("%d", d[(1 << n) - 1]);
}
