#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
const int maxn = 20;
int d[1 << (maxn + 1)], a[maxn][maxn];
string s[maxn];
int lowzero(int S) {
  for (int i = 0; i < maxn; i++)
    if (!((S >> i) & 1)) return i;
  return maxn - 1;
}
int main(int argc, char const *argv[]) {
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cin >> a[i][j];
    for (int i = (1 << n) - 1; i > 0; i--) d[i] = inf;
    d[0] = 0;
    int M = 1 << n;
    for (int S = 0; S < M; S++) {
      int bit = lowzero(S);
      for (int c = 0; c < m; c++) {
        d[S | (1 << bit)] = min(d[S | (1 << bit)], d[S] + a[bit][c]);
        int sum = 0, mw = 0, bits = 0;
        for (int r = 0; r < n; r++)
          if (s[bit][c] == s[r][c]) {
            sum += a[r][c];
            mw = max(mw, a[r][c]);
            bits |= 1 << r;
          }
        d[S | bits] = min(d[S | bits], d[S] + sum - mw);
      }
    }
    cout << d[M - 1] << endl;
  }
  return 0;
}
