#include <bits/stdc++.h>
using namespace std;
char s[30][30];
int a[30][30];
int bit[30][30], cost[30][30], dp[(1 << 21) + 1];
int main() {
  int n, m;
  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 ans = 0, mx = -1;
      for (int k = 0; k < n; k++) {
        if (s[i][j] == s[k][j]) {
          ans += a[k][j];
          mx = max(mx, a[k][j]);
          bit[i][j] |= (1 << k);
        }
      }
      cost[i][j] = ans - mx;
    }
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      if ((i & (1 << j)) == 0) {
        for (int k = 0; k < m; k++) {
          dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + a[j][k]);
          dp[i | bit[j][k]] = min(dp[i | bit[j][k]], dp[i] + cost[j][k]);
        }
      }
    }
  }
  cout << dp[(1 << n) - 1] << endl;
}
