#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 20;
int mi2[20], _mi2[maxn];
int n, m;
char s[21][21];
int a[21][21];
int sv[21][21], c[21][21];
int f[maxn];
int main() {
  _mi2[mi2[0] = 1] = 0;
  for (int i = (1); i <= (19); ++i) mi2[i] = mi2[i - 1] * 2, _mi2[mi2[i]] = i;
  for (int i = 1, nn = 1 << 20; i < nn; ++i)
    if (!_mi2[i]) _mi2[i] = _mi2[i - 1];
  scanf("%d%d", &n, &m);
  for (int i = (0); i <= (n - 1); ++i) scanf("%s", s[i]);
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (m - 1); ++j) scanf("%d", &a[i][j]);
  for (int i = (0); i <= (n - 1); ++i)
    for (int j = (0); j <= (m - 1); ++j) {
      int mx = 0;
      for (int k = (0); k <= (n - 1); ++k)
        if (s[i][j] == s[k][j]) {
          sv[i][j] |= mi2[k];
          c[i][j] += a[k][j];
          mx = max(mx, a[k][j]);
        }
      c[i][j] -= mx;
    }
  int nn = 1 << n;
  --nn;
  for (int _ = 1, u, ww; _ <= nn; ++_) {
    f[_] = 0x7fffffff;
    ww = _ & (-_);
    u = _mi2[ww];
    for (int i = (0); i <= (m - 1); ++i) {
      f[_] = min(f[_], f[_ - ww] + a[u][i]);
      f[_] = min(f[_], f[_ & (_ ^ sv[u][i])] + c[u][i]);
    }
  }
  cout << f[nn] << endl;
  return 0;
}
