#include <bits/stdc++.h>
const int MaxN = 1 << 20;
using namespace std;
int dp[MaxN + 5];
char s[30][30];
int a[30][30], cost[30][30];
int bit[30][30];
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", &a[i][j]);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int Max = 0, tmp = 0;
        bit[i][j] = 0;
        for (int k = 0; k < n; k++) {
          if (s[k][j] == s[i][j]) {
            Max = max(Max, a[k][j]);
            tmp += a[k][j];
            bit[i][j] |= (1 << k);
          }
        }
        cost[i][j] = tmp - Max;
      }
    }
    for (int i = 0; i < (1 << n); i++) dp[i] = 1 << 29;
    dp[0] = 0;
    for (int i = 0; i < (1 << n); i++) {
      for (int j = 0; j < n; j++) {
        if ((i & (1 << j)) == 0) {
          for (int k = 0; k < m; k++) {
            dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + a[j][k]);
            dp[i | bit[j][k]] = min(dp[i | bit[j][k]], dp[i] + cost[j][k]);
          }
        }
      }
    }
    printf("%d\n", dp[(1 << n) - 1]);
  }
  return 0;
}
