#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 1e3 + 5;
const int mod = 1e9 + 7;
int a[21][21], g[21][26], u[21][26];
int f[(1 << 20) + 5];
char ch[21][21];
inline void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", ch[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int j = 0; j < m; j++) {
    int sum = 0;
    for (int k = 0; k < 26; k++) {
      int Max = 0;
      g[j][k] = u[j][k] = 0;
      for (int i = 0; i < n; i++)
        if (ch[i][j] - 'a' == k) {
          u[j][k] += a[i][j];
          Max = max(Max, a[i][j]);
          g[j][k] |= (1 << i);
        }
      u[j][k] -= Max;
    }
  }
  memset(f, 0x3f, sizeof f);
  f[0] = 0;
  int tot = (1 << n);
  for (int s = 0; s < tot; s++) {
    for (int i = 0; i < n; i++) {
      int T = (1 << i);
      if (!(s & T)) {
        for (int j = 0; j < m; j++) {
          f[s | T] = min(f[s | T], f[s] + a[i][j]);
          int c = ch[i][j] - 'a';
          f[s | g[j][c]] = min(f[s | g[j][c]], f[s] + u[j][c]);
        }
        break;
      }
    }
  }
  printf("%d\n", f[tot - 1]);
}
int main() {
  solve();
  return 0;
}
