#include <bits/stdc++.h>
using namespace std;
char s[21][21];
int cost[21][21];
int sum[21][26];
int other[21][26];
int dp[(1 << 21)];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> s[i][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> cost[i][j];
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      sum[j][s[i][j] - 'a'] += cost[i][j];
      other[j][s[i][j] - 'a'] |= (1 << i);
    }
  }
  for (int i = 1; i < (1 << n); i++) {
    dp[i] = 1e9;
  }
  for (int j = 0; j < m; j++) {
    for (int mask = 0; mask < (1 << n); mask++) {
      for (int i = 0; i < n; i++) {
        if (!((mask >> i) & 1) && dp[mask] != 1e9) {
          dp[mask | (1 << i)] = min(dp[mask | (1 << i)], dp[mask] + cost[i][j]);
          dp[mask | other[j][s[i][j] - 'a']] =
              min(dp[mask | other[j][s[i][j] - 'a']],
                  dp[mask] + sum[j][s[i][j] - 'a'] - cost[i][j]);
        }
      }
    }
  }
  cout << dp[(1 << n) - 1];
}
