#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
long long powm(long long a, long long p, long long m) {
  long long r = 1 % m;
  while (p) {
    if (p & 1) r = r * a % m;
    p >>= 1;
    a = a * a % m;
  }
  return r;
}
int n, m, dp[1 << 20], a[20][20], masks[20][20], sums[20][20];
char t[20][21];
int calc(int mask) {
  int &res = dp[mask];
  if (res != -1) return res;
  res = inf;
  for (int i = 0; i < (n); ++i)
    if (mask & (1 << i)) {
      int nmask = mask - (1 << i);
      for (int j = 0; j < (m); ++j) {
        if (sums[i][j] == 0)
          res = min(res, calc(nmask));
        else
          res = min(res, min(a[i][j] + calc(nmask),
                             sums[i][j] + calc(nmask & (~masks[i][j]))));
      }
    }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (n); ++i) scanf("%s", t[i]);
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) scanf("%d", a[i] + j);
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  int mask = 0;
  for (int i = 0; i < (n); ++i) {
    int cnt = 0;
    for (int j = 0; j < (m); ++j) {
      for (int k = 0; k < (n); ++k) cnt += k != i && t[i][j] == t[k][j];
      if (cnt) {
        mask |= 1 << i;
        break;
      }
    }
  }
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j)
      for (int k = 0; k < (n); ++k)
        if (i != k && t[i][j] == t[k][j]) {
          sums[i][j] += a[k][j];
          masks[i][j] |= 1 << k;
        }
  printf("%d\n", calc((1 << n) - 1));
  return 0;
}
