#include <bits/stdc++.h>
int n, m;
int table[(1 << 20) + 10];
int lowbit[(1 << 20) + 10];
int ba[35][35];
int cost[35][35];
int same[35][35];
char st[35][35];
int min(int x, int y) {
  if (x < y)
    return x;
  else
    return y;
}
int main() {
  int i, a, j;
  scanf("%d%d\n", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s\n", st[i] + 1);
  }
  for (i = 1; i <= n; i++) {
    for (a = 1; a <= m; a++) {
      scanf("%d", &ba[i][a]);
    }
  }
  for (i = 1; i <= n; i++) {
    for (a = 1; a <= m; a++) {
      int coma = 0;
      for (j = 1; j <= n; j++) {
        if (st[i][a] == st[j][a]) {
          same[i][a] |= 1 << (j - 1);
          cost[i][a] += ba[j][a];
          if (coma < ba[j][a]) coma = ba[j][a];
        }
      }
      cost[i][a] -= coma;
    }
  }
  for (i = 1; i <= 1 << n; i++) {
    table[i] = 100000000;
    for (a = 1; a <= n; a++) {
      if (i >> (a - 1) & 1) {
        lowbit[i] = a;
        break;
      }
    }
  }
  table[0] = 0;
  for (a = 1; a < 1 << n; a++) {
    for (i = 1; i <= m; i++) {
      table[a] =
          min(table[a], table[a ^ (1 << (lowbit[a] - 1))] + ba[lowbit[a]][i]);
      table[a] = min(table[a],
                     table[a & (a ^ same[lowbit[a]][i])] + cost[lowbit[a]][i]);
    }
  }
  printf("%d\n", table[(1 << n) - 1]);
  return 0;
}
