#include <bits/stdc++.h>
template <class T>
inline bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool cmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
using namespace std;
const int N = 25, L = (1 << 20) + 5, inf = 0x3f3f3f3f;
char s[N][N];
int f[L], a[N][N], n, m, lim;
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = (0), I = (n - 1) + 1; i < I; ++i) scanf("%s", s[i]);
  for (register int i = (0), I = (n - 1) + 1; i < I; ++i)
    for (register int j = (0), I = (m - 1) + 1; j < I; ++j)
      scanf("%d", &a[i][j]);
  memset(f, 0x3f, sizeof(f));
  lim = (1 << n) - 1, f[0] = 0;
  for (int i = 0; i < lim; i++)
    for (int j = 0; j < n; j++)
      if (!((i >> j) & 1)) {
        for (int k = 0; k < m; k++) {
          f[i | (1 << j)] = min(f[i | (1 << j)], f[i] + a[j][k]);
          int add = 0;
          int maxx = 0;
          int change = 0;
          for (int l = 0; l < n; l++) {
            if (s[j][k] == s[l][k]) {
              add += a[l][k];
              maxx = max(maxx, a[l][k]);
              change |= (1 << l);
            }
          }
          f[i | change] = min(f[i | change], f[i] + add - maxx);
        }
        break;
      }
  printf("%d\n", f[lim]);
  return 0;
}
