#include <bits/stdc++.h>
using namespace std;
int dp[1 << 21], cost[21][21], v[21][21], n, m, val[21][21], _max;
char str[21][21];
int main() {
  while (~scanf("%d %d", &n, &m)) {
    getchar();
    memset(val, 0, sizeof(val));
    memset(v, 0, sizeof(v));
    for (int i = 0; i < n; i++) scanf("%s", str[i]);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) scanf("%d", &cost[i][j]);
    }
    for (int j = 0; j < m; j++) {
      for (int i = 0; i < n; i++) {
        _max = 0;
        for (int k = 0; k < n; k++) {
          if (str[i][j] == str[k][j]) {
            val[i][j] |= (1 << k);
            _max = max(_max, cost[k][j]);
            v[i][j] += cost[k][j];
          }
        }
        v[i][j] -= _max;
      }
    }
    _max = (1 << n);
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 0; i < _max; i++) {
      for (int j = 0; j < n; j++) {
        if ((i & (1 << j)) == 0) {
          for (int lie = 0; lie < m; lie++) {
            dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + cost[j][lie]);
            dp[i | val[j][lie]] = min(dp[i | val[j][lie]], dp[i] + v[j][lie]);
          }
        }
      }
    }
    printf("%d\n", dp[_max - 1]);
  }
}
