#include <bits/stdc++.h>
using namespace std;
char s[20][25];
int c[20][20], g[20][20], a[20][20];
int D[1 << 20];
int main(int argc, const char* argv[]) {
  int n, m;
  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]);
  for (int k = 0; k < m; ++k) {
    for (int i = 0; i < n; ++i) {
      int max = 0;
      for (int j = 0; j < n; ++j) {
        if (s[i][k] == s[j][k]) {
          c[i][k] += a[j][k];
          g[i][k] |= 1 << j;
          if (max < a[j][k]) max = a[j][k];
        }
      }
      c[i][k] -= max;
    }
  }
  for (int mask = 1; mask < (1 << n); ++mask) {
    D[mask] = 20000000;
    int i;
    for (int j = 0; j < n; ++j) {
      if (mask & (1 << j)) {
        i = j;
        break;
      }
    }
    for (int j = 0; j < m; ++j) {
      D[mask] = min(D[mask], D[mask ^ (1 << i)] + a[i][j]);
      D[mask] = min(D[mask], D[mask & (mask ^ g[i][j])] + c[i][j]);
    }
  }
  printf("%d", D[(1 << n) - 1]);
  return 0;
}
