#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 dp[1100000];
int ed, st;
void yuchuli() {
  int dada;
  ed = (1 << n) - 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dada = 0;
      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;
    }
  }
}
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() {
  int f, f2;
  yuchuli();
  memset((dp), 127, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i < ed; i++) {
    for (int j = 0; j < n; j++) {
      if (!(i & (1 << j))) {
        f = 1 << j;
        for (int k = 0; k < m; k++) {
          dp[i | f] = min(dp[i | f], dp[i] + a[j][k]);
          f2 = msx[j][k];
          dp[i | f2] = min(dp[i | f2], dp[i] + msa[j][k]);
        }
      }
    }
  }
  cout << dp[ed] << endl;
}
int main() {
  int nn = 1;
  while (nn--) {
    init(), read(), solve();
  }
  return 0;
}
