#include <bits/stdc++.h>
using namespace std;
int dp[1 << 20], cost[22][22], conflicts[22][22], change[22][22];
char s[22][22];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    getchar();
    scanf("%s", s[i]);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &cost[i][j]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if (s[i][k] == s[j][k]) conflicts[i][k] += (1 << j);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int sum = 0, mx = 0;
      for (int k = 0; k < n; k++) {
        if (s[i][j] == s[k][j]) {
          sum += cost[k][j], mx = max(mx, cost[k][j]);
        }
      }
      change[i][j] = sum - mx;
    }
  }
  for (int i = 0; i < (1 << n); i++) dp[i] = 1000000000;
  dp[0] = 0;
  for (int mask = 1; mask < (1 << n); mask++) {
    int index = -1;
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        index = i;
        break;
      }
    }
    for (int i = 0; i < m; i++) {
      int newMask = mask - (conflicts[index][i] & mask);
      dp[mask] = min(dp[mask], dp[newMask] + change[index][i]);
      dp[mask] = min(dp[mask], dp[mask ^ (1 << index)] + cost[index][i]);
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
