#include <bits/stdc++.h>
using namespace std;
int n, m, dp[1 << 21], a[21][21], sum[21][21], b[21][21];
char M[21][21];
int solve(int s) {
  if (dp[s] != -1) return dp[s];
  dp[s] = 1 << 30;
  for (int i = 0; i < n; i++)
    if (s & (1 << i)) {
      int state = s ^ (1 << i), t = 1 << 30;
      for (int j = 0; j < m; j++)
        dp[s] = min(dp[s], solve(s & (~b[i][j])) + sum[i][j]);
      for (int j = 0; j < m; j++) t = min(t, a[i][j]);
      dp[s] = min(dp[s], solve(state) + t);
    }
  return dp[s];
}
int main() {
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) scanf("%s", M[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 ma = 0;
        sum[i][j] = b[i][j] = 0;
        for (int k = 0; k < n; k++)
          if (M[i][j] == M[k][j]) {
            sum[i][j] += a[k][j];
            ma = max(ma, a[k][j]);
            b[i][j] |= (1 << k);
          }
        sum[i][j] -= ma;
      }
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    printf("%d\n", solve((1 << n) - 1));
  }
}
