#include <bits/stdc++.h>
using namespace std;
int n, m, mp[22][22], same[22][22], cost[22][22], dp[(1 << 20) + 5];
char s[22][22];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) cin >> s[i] + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", mp[i] + j);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int sum = 0, maxx = 0;
      for (int k = 1; k <= n; k++)
        if (s[i][j] == s[k][j]) {
          sum += mp[k][j];
          maxx = max(maxx, mp[k][j]);
          same[i][j] |= (1 << (k - 1));
        }
      cost[i][j] = sum - maxx;
    }
  memset(dp, 127, sizeof(dp));
  dp[0] = 0;
  for (int state = 0; state < (1 << n); state++) {
    for (int i = 1; i <= n; i++) {
      if (state & (1 << (i - 1))) continue;
      for (int j = 1; j <= m; j++) {
        dp[state | (1 << (i - 1))] =
            min(dp[state | (1 << (i - 1))], dp[state] + mp[i][j]);
        dp[state | same[i][j]] =
            min(dp[state | same[i][j]], dp[state] + cost[i][j]);
      }
    }
  }
  printf("%d", dp[(1 << n) - 1]);
  return 0;
}
