#include <bits/stdc++.h>
using namespace std;
int dp[1 << 21];
char s[26][26];
int c[26][26];
int v[26][26];
int state[26][26];
int n, m;
int main() {
  while (~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", &c[i][j]);
    int total = (1 << n) - 1;
    for (int i = 0; i < n; i++)
      for (int k = 0; k < m; k++) {
        int maxn = 0;
        for (int j = 0; j < n; j++) {
          if (s[i][k] != s[j][k]) continue;
          v[i][k] += c[j][k];
          maxn = max(c[j][k], maxn);
          state[i][k] |= 1 << j;
        }
        v[i][k] -= maxn;
      }
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 0; i < total; i++)
      for (int j = 0;; j++)
        if (!((i >> j) & 1)) {
          int a = 1 << j;
          for (int k = 0; k < m; k++) {
            int b = state[j][k];
            dp[i | a] = min(dp[i | a], dp[i] + c[j][k]);
            dp[i | b] = min(dp[i | b], dp[i] + v[j][k]);
          }
          break;
        }
    printf("%d\n", dp[total]);
  }
}
