#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<string> s(n);
  for (string &e : s) cin >> e;
  vector<vector<int> > a(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  vector<int> dp(1 << n, (1 << 30));
  vector<vector<int> > cost(n, vector<int>(m, 0)), masks(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int max_a = 0;
      for (int k = 0; k < n; k++)
        if (s[i][j] == s[k][j]) {
          max_a = max(max_a, a[k][j]);
          cost[i][j] += a[k][j];
          masks[i][j] |= (1 << k);
        }
      cost[i][j] -= max_a;
    }
  dp[0] = 0;
  for (int mask = 1; mask < (1 << n); mask++) {
    int j = 0;
    for (; j < n; j++)
      if (mask & (1 << j)) break;
    for (int i = 0; i < m; i++) {
      dp[mask] = min(dp[mask], dp[mask & (mask ^ masks[j][i])] + cost[j][i]);
      dp[mask] = min(dp[mask], dp[mask ^ (1 << j)] + a[j][i]);
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
  return 0;
}
