#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[22][22];
int cost[22][22];
int rev_st[22][22];
int rev_ct[22][22];
int dp[1 << 20];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", str[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 < m; ++j) {
      int cnt = 0;
      for (int k = 0; k < n; ++k)
        if (str[i][j] == str[k][j]) {
          cnt++;
          rev_st[i][j] |= (1 << k);
          if (i != k) rev_ct[i][j] += cost[k][j];
        }
      if (cnt == 0) cost[i][j] = 0;
    }
  memset(dp, 63, sizeof(dp));
  dp[0] = 0;
  for (int j = 0; j < m; ++j)
    for (int i = 0; i < n; ++i) {
      for (int st = 0; st < (1 << n); ++st) {
        dp[st | (1 << i)] = min(dp[st | (1 << i)], dp[st] + cost[i][j]);
        dp[st | rev_st[i][j]] =
            min(dp[st | rev_st[i][j]], dp[st] + rev_ct[i][j]);
      }
    }
  printf("%d\n", dp[(1 << n) - 1]);
}
