#include <bits/stdc++.h>
using namespace std;
int dp[1 << 20];
int main() {
  string s[22];
  int n, m, f[22][22], cost[22][22], b[22][22];
  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 >> f[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int sum = 0, mx = 0, bit = 0;
      for (int k = 0; k < n; k++) {
        if (s[k][j] == s[i][j]) {
          sum += f[k][j];
          mx = max(f[k][j], mx);
          bit += (1 << k);
        }
      }
      b[i][j] = bit;
      cost[i][j] = sum - mx;
    }
  }
  int mask = (1 << n) - 1;
  memset(dp, 0x3f, sizeof dp);
  dp[0] = 0;
  for (int st = 1; st <= mask; st++) {
    int fs = 0;
    for (int i = 0; i < n; i++)
      if ((st >> i) & 1) {
        fs = i;
        break;
      }
    for (int i = 0; i < m; i++) {
      dp[st] = min(dp[st], dp[st ^ (1 << fs)] + f[fs][i]);
      dp[st] = min(dp[st], dp[st ^ (st & b[fs][i])] + cost[fs][i]);
    }
  }
  cout << dp[mask];
  return 0;
}
