#include <bits/stdc++.h>
const int MOD = 9973;
const int INF = 99999999;
using namespace std;
int n, m;
char s[25][25];
int a[25][25];
int cost[25][25];
int bit[25][25];
int dp[1 << 20];
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]);
    memset(bit, 0, sizeof(bit));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int sum = 0;
        int max_cost = -1;
        for (int k = 0; k < n; k++) {
          if (s[i][j] == s[k][j]) {
            sum += a[k][j];
            max_cost = max(max_cost, a[k][j]);
            bit[i][j] |= (1 << k);
          }
        }
        sum -= max_cost;
        cost[i][j] = sum;
      }
    }
    for (int i = 0; i < (1 << n); i++) dp[i] = INF;
    dp[0] = 0;
    for (int k = 0; k < m; k++) {
      for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
          if (i & (1 << j)) continue;
          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;
}
