#include <bits/stdc++.h>
using namespace std;
int dp[1 << 21];
int cost[30][30], num[30][30];
int nex[30][30];
char s[30][30];
int n, m, all;
void init() {
  all = (1 << n) - 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int val = all;
      for (int k = 0; k < n; k++) {
        if (s[i][j] == s[k][j]) {
          val -= (1 << k);
          if (i != k) cost[i][j] += num[k][j];
        }
      }
      nex[i][j] = val;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &num[i][j]);
    }
  }
  init();
  int ret = all;
  for (int i = 0; i < n; i++) {
    int ok = 1;
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++)
        if (k != i) {
          if (s[i][j] == s[k][j]) ok = 0;
        }
    }
    if (ok) ret -= (1 << i);
  }
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  dp[ret] = 0;
  for (int s = ret; s > 0; s--) {
    for (int i = 0; i < n; i++) {
      if ((s & (1 << i)) == 0) continue;
      int s1 = s ^ (1 << i);
      for (int j = 0; j < m; j++) {
        dp[s1] = min(dp[s1], dp[s] + num[i][j]);
        int s2 = s1 & nex[i][j];
        dp[s2] = min(dp[s2], dp[s] + cost[i][j]);
      }
    }
  }
  printf("%d\n", dp[0]);
  return 0;
}
