#include <bits/stdc++.h>
const int INF = 0x7F7F7F7F;
const double EPS = 1e-10;
const long long mod7 = 1e9 + 7;
const long long mod9 = 1e9 + 9;
using namespace std;
inline long long rit() {
  long long f = 0, key = 1;
  char c;
  do {
    c = getchar();
    if (c == '-') key = -1;
  } while (c < '0' || c > '9');
  do {
    f = f * 10 + c - '0';
    c = getchar();
  } while (c >= '0' && c <= '9');
  return f * key;
}
inline void fprt(double f) { printf("%.08lf", f); }
void init() {}
const int Z = 22;
int n, m;
char c[Z][Z];
int a[Z][Z];
int msx[Z][Z];
int msa[Z][Z];
int ans[1100000];
int ed, st;
int ask(int x) {
  if (x == ed) return 0;
  if (ans[x] != -1) return ans[x];
  ans[x] = INF;
  for (int i = 0; i < n; i++) {
    if (!(x & (1 << i))) {
      for (int k = 0; k < m; k++) {
        ans[x] = min(ans[x], ask(x | (1 << i)) + a[i][k]);
        ans[x] = min(ans[x], ask(x | (msx[i][k])) + msa[i][k]);
      }
    }
  }
  return ans[x];
}
void yuchuli() {
  int dada;
  ed = (1 << n) - 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dada = 00;
      msx[i][j] = 1 << i;
      for (int k = 0; k < n; k++) {
        if (c[i][j] == c[k][j]) {
          msx[i][j] |= (1 << k);
          msa[i][j] += a[k][j];
          dada = max(dada, a[k][j]);
        }
      }
      msa[i][j] -= dada;
      if (msx[i][j] == i) st |= (1 << i);
    }
  }
}
void read() {
  n = rit(), m = rit();
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) a[i][j] = rit();
}
void solve() {
  yuchuli();
  memset((ans), -1, sizeof((ans)));
  cout << ask(st) << endl;
}
int main() {
  int nn = 1;
  while (nn--) {
    init(), read(), solve();
  }
  return 0;
}
