#include <bits/stdc++.h>
int a[22][22];
int f[1 << 20];
int cost[22][22];
int state[22][22];
char s[22][22];
void Min(int &x, int y) {
  if (x == -1 || y < x) {
    x = y;
  }
}
int main() {
  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 i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int sum = 0, mx = 0;
      for (int k = 0; k < n; k++)
        if (s[k][j] == s[i][j]) {
          if (a[k][j] > mx) {
            mx = a[k][j];
          }
          sum += a[k][j];
          state[i][j] |= 1 << k;
        }
      cost[i][j] = sum - mx;
    }
  }
  memset(f, -1, sizeof(f));
  f[0] = 0;
  for (int i = 0; i < (1 << n); i++)
    if (f[i] != -1) {
      int id = -1;
      for (int j = 0; j < n; j++)
        if (!(i >> j & 1)) {
          id = j;
          break;
        }
      if (id == -1) {
        break;
      }
      for (int k = 0; k < m; k++) {
        Min(f[i | (1 << id)], f[i] + a[id][k]);
        Min(f[i | state[id][k]], f[i] + cost[id][k]);
      }
    }
  printf("%d\n", f[(1 << n) - 1]);
  return 0;
}
