#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n, m;
vector<string> input;
int dp[1 << 20];
int cost[20][20];
int search(int idx) {
  int& ret = dp[idx];
  if (ret != -1) return ret;
  if (idx == 0) return 0;
  int ret2 = INT_MAX;
  int idx1 = idx;
  int nIdx1 = 0;
  for (int i = 20; i >= 0; i--) {
    if (idx1 & (1 << i)) {
      nIdx1 = i;
      idx1 -= (1 << i);
      break;
    }
  }
  int idx2 = idx & ~(1 << nIdx1);
  int ret1 = search(idx2);
  for (int i = 0; i < (int)m; i++) {
    idx2 = idx & ~(1 << nIdx1);
    ret2 = min(ret2, cost[nIdx1][i] + ret1);
    int sum = 0, maxV = 0;
    for (int j = 0; j < (int)n; j++)
      if (input[j][i] == input[nIdx1][i]) {
        sum += cost[j][i];
        idx2 &= ~(1 << j);
        maxV = max(maxV, cost[j][i]);
      }
    ret2 = min(ret2, sum - maxV + search(idx2));
  }
  return ret = ret2;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> m;
  for (int i = 0; i < (int)n; i++) {
    string s;
    cin >> s;
    input.push_back(s);
  }
  for (int i = 0; i < (int)n; i++)
    for (int j = 0; j < (int)m; j++) cin >> cost[i][j];
  cout << search((1 << n) - 1) << endl;
  int a = 3;
}
