#include <bits/stdc++.h>
using namespace std;
int dp[(1 << 20 | 7)];
int input[25][25];
char c[25][25];
int sum2[25][25];
int sum3[25][25];
int n, m, maxx;
int lowbit(int x) {
  for (int i = 0; i < 32; i++) {
    if (x & 1) return i;
    x >>= 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int r = 0; r < m; r++) cin >> c[i][r];
  for (int i = 0; i < n; i++)
    for (int r = 0; r < m; r++) scanf("%d", &input[i][r]);
  for (int i = 0; i < m; i++)
    for (int r = 0; r < n; r++) {
      int sum = 0, plk = 0;
      maxx = 0;
      for (int k = 0; k < n; k++)
        if (c[r][i] == c[k][i]) {
          sum += input[k][i];
          maxx = max(maxx, input[k][i]);
          plk += (1 << k);
        }
      sum2[r][i] = sum - maxx;
      sum3[r][i] = plk;
    }
  memset(dp, 0X3f, sizeof(dp));
  dp[(1 << n) - 1] = 0;
  for (int plk = (1 << n) - 1; plk > 0; plk--) {
    int pos = lowbit(plk);
    int last = (1 << pos);
    for (int r = 0; r < m; r++) {
      dp[plk - last] = min(dp[plk - last], dp[plk] + input[pos][r]);
      dp[plk & (~sum3[pos][r])] =
          min(dp[plk & (~sum3[pos][r])], dp[plk] + sum2[pos][r]);
    }
  }
  cout << dp[0];
}
