#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[25][25];
int a[25][25], d[1 << 20], ma[25][25], c[25][25];
const int INF = 1e9;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(n); ++i) scanf("%s", s[i]);
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(m); ++j) scanf("%d", a[i] + j);
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(m); ++j) {
      int &mask = ma[i][j], &cost = c[i][j], mx = 0;
      for (int k = 0; k < (int)(n); ++k)
        if (s[k][j] == s[i][j]) {
          cost += a[k][j];
          mask |= 1 << k;
          mx = max(mx, a[k][j]);
        }
      cost -= mx;
    }
  for (int i = 0; i < (int)(1 << n); ++i) d[i] = INF;
  d[0] = 0;
  for (int mask = 0; mask < (int)((1 << n) - 1); ++mask) {
    int i = 0;
    while (mask & (1 << i)) ++i;
    for (int j = 0; j < (int)(m); ++j) {
      d[mask | ma[i][j]] = min(d[mask | ma[i][j]], d[mask] + c[i][j]);
      d[mask | (1 << i)] = min(d[mask | (1 << i)], d[mask] + a[i][j]);
    }
  }
  printf("%d\n", d[(1 << n) - 1]);
  return 0;
}
