#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  x = c - 'a' + 1;
}
int cnt(int x) {
  int res = 1;
  while (x & 1) x >>= 1, ++res;
  return res;
}
int n, m, ch[23][23], cost[23][23], cover[23][23], give[23][23], f[2097152];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) read(ch[i][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", cost[i] + j);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int h = 0;
      for (int k = 1; k <= n; ++k) {
        if (ch[i][j] == ch[k][j])
          cover[i][j] |= (1 << k >> 1), give[i][j] += cost[k][j],
              h = max(h, cost[k][j]);
      }
      give[i][j] -= h;
    }
  }
  memset(f, 63, sizeof(f));
  f[0] = 0;
  for (int i = 0, j; i < (1 << n) - 1; ++i) {
    j = cnt(i);
    for (int k = 1; k <= m; ++k) {
      f[i | (1 << j >> 1)] = min(f[i | (1 << j >> 1)], f[i] + cost[j][k]);
      f[i | cover[j][k]] = min(f[i | cover[j][k]], f[i] + give[j][k]);
    }
  }
  printf("%d\n", f[(1 << n) - 1]);
  return 0;
}
