#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxn = 21;
char s[maxn][maxn];
int dp[1 << maxn], a[maxn][maxn], cost[maxn][maxn], same[maxn][maxn];
int main() {
  int n, m;
  ios::sync_with_stdio(false);
  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 >> a[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int sum = 0, ma = 0;
      for (int k = 0; k < n; k++) {
        if (s[i][j] == s[k][j]) {
          sum += a[k][j];
          ma = max(ma, a[k][j]);
          same[i][j] |= (1 << k);
        }
      }
      cost[i][j] = sum - ma;
    }
  }
  for (int i = 1; i < (1 << n); i++) dp[i] = inf;
  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + a[j][k]);
        dp[i | same[j][k]] = min(dp[i | same[j][k]], dp[i] + cost[j][k]);
      }
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}
