#include <bits/stdc++.h>
using namespace std;
int A[25][25], N, M, D[1100000], l, n, t, h;
string S[25];
int main() {
  cin >> N >> M;
  for (int i = 0; i <= N - 1; i++) cin >> S[i];
  for (int i = 0; i <= N - 1; i++)
    for (int j = 0; j <= M - 1; j++) cin >> A[i][j];
  for (int i = 1; i <= (1 << N) - 1; i++) D[i] = 50000000;
  for (int m = 0; m <= (1 << N) - 1; m++) {
    for (int b = 0; b <= N - 1; b++)
      if (!(m & (1 << b))) {
        l = b;
        break;
      }
    for (int c = 0; c <= M - 1; c++) {
      D[m + (1 << l)] = min(D[m + (1 << l)], D[m] + A[l][c]), n = m, t = 0,
                  h = 0;
      for (int i = 0; i <= N - 1; i++)
        if (S[l][c] == S[i][c]) n |= 1 << i, t += A[i][c], h = max(h, A[i][c]);
      D[n] = min(D[n], D[m] + t - h);
    }
  }
  cout << D[(1 << N) - 1];
}
