#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n, m, cost[N][N], c[N][N], dp[1 << N], b[N][N];
char a[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  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) cin >> cost[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 (a[i][j] == a[k][j]) {
          b[i][j] |= (1 << k);
          c[i][j] += cost[k][j];
          mx = max(mx, cost[k][j]);
        }
      c[i][j] -= mx;
    }
  for (int mask = 0; mask < (1 << n); ++mask) dp[mask] = (int)1e9;
  dp[0] = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    int bit = 0;
    for (int i = 0; i < n; ++i)
      if ((1 << i) & mask)
        ;
      else {
        bit = i;
        break;
      }
    for (int i = 0; i < m; ++i) {
      dp[mask | (1 << bit)] =
          min(dp[mask | (1 << bit)], dp[mask] + cost[bit][i]);
      dp[mask | b[bit][i]] = min(dp[mask | b[bit][i]], dp[mask] + c[bit][i]);
    }
  }
  cout << dp[(1 << n) - 1];
}
