#include <bits/stdc++.h>
using namespace std;
int a[23][23];
char s[23][23];
int dp[1 << 23];
int n, m;
int cost[23][23];
int st[23][23];
int main() {
  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 mx = -0x3f3f3f3f;
      int ans = 0;
      for (int k = 0; k < n; k++) {
        if (s[i][j] == s[k][j]) {
          ans += a[k][j];
          mx = max(mx, a[k][j]);
          st[i][j] |= 1 << k;
        }
      }
      ans -= mx;
      cost[i][j] = ans;
    }
  for (int i = 1; i < (1 << n); i++) dp[i] = 0x3f3f3f3f;
  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 | st[j][k]] = min(dp[i | st[j][k]], dp[i] + cost[j][k]);
        }
      }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
