#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[20][21];
int a[20][20];
int g[20][20], cost[20][20];
int dp[1 << 20];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  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];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int mx = 0;
      for (int k = 0; k < n; k++) {
        if (s[i][j] == s[k][j]) {
          g[i][j] |= 1 << k;
          cost[i][j] += a[k][j];
          mx = max(mx, a[k][j]);
        }
      }
      cost[i][j] -= mx;
    }
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  for (int s = 0; s < 1 << n; s++) {
    int lb = -1;
    for (int i = 0; i < n; i++)
      if (s >> i & 1 ^ 1) {
        lb = i;
        break;
      }
    if (lb != -1)
      for (int i = 0; i < m; i++) {
        dp[s | 1 << lb] = min(dp[s | 1 << lb], dp[s] + a[lb][i]);
        dp[s | g[lb][i]] = min(dp[s | g[lb][i]], dp[s] + cost[lb][i]);
      }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}
