#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[20][20 + 1];
int a[20][20];
int dp[1 << 20];
void chkmin(int &a, int b) {
  if (a > b) a = b;
}
const int inf = 0x3f3f3f3f;
int sum[1 << 20][20], mx[1 << 20][20];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  int f[20][20] = {};
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++)
        if (s[i][j] == s[k][j]) f[i][j] |= (1 << k);
    }
  for (int j = 0; j < m; j++) {
    for (int mask = 1; mask < (1 << n); mask++) {
      int k = __builtin_ctz(mask);
      sum[mask][j] = sum[mask ^ (1 << k)][j] + a[k][j];
      mx[mask][j] = max(mx[mask ^ (1 << k)][j], a[k][j]);
    }
  }
  memset(dp, 63, sizeof dp);
  dp[0] = 0;
  for (int mask = 1; mask < (1 << n); mask++) {
    int k = __builtin_ctz(mask);
    for (int j = 0; j < m; j++) {
      chkmin(dp[mask], dp[mask ^ (1 << k)] + a[k][j]);
      chkmin(dp[mask],
             dp[mask ^ (f[k][j] & mask)] + sum[f[k][j]][j] - mx[f[k][j]][j]);
    }
  }
  cout << dp[(1 << n) - 1];
}
