#include <bits/stdc++.h>
using namespace std;
int a[25][25], n, m, dp[1 << 22];
char s[25][222];
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]);
  memset(dp, 63, sizeof(dp)), dp[0] = 0;
  for (int l, msk = 0; msk < (1 << n); ++msk) {
    for (int b = 0; b < n; ++b)
      if (!(msk & (1 << b))) {
        l = b;
        break;
      }
    for (int c = 0; c < m; ++c) {
      dp[msk + (1 << l)] = min(dp[msk + (1 << l)], dp[msk] + a[l][c]);
      int t = 0, h = 0, tmsk = msk;
      for (int i = 0; i < n; ++i)
        if (s[i][c] == s[l][c])
          tmsk |= (1 << i), t += a[i][c], h = max(h, a[i][c]);
      dp[tmsk] = min(dp[tmsk], dp[msk] + t - h);
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
}
