#include <bits/stdc++.h>
using namespace std;
int a[25][25], N, M, dp[1 << 22], l, n, m, t, h, i, j, b, c;
string s[25];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (i = 0; i < N; ++i) cin >> s[i];
  for (i = 0; i < N; ++i)
    for (j = 0; j < M; ++j) cin >> a[i][j];
  memset(dp, 63, sizeof(dp));
  dp[0] = 0;
  for (m = 0; m < (1 << N); ++m) {
    for (b = 0; b < N; ++b)
      if (!(m & (1 << b))) {
        l = b;
        break;
      }
    for (c = 0; c < M; ++c) {
      dp[m + (1 << l)] = min(dp[m + (1 << l)], dp[m] + a[l][c]), n = m, t = 0,
                   h = 0;
      for (i = 0; i < N; ++i)
        if (s[i][c] == s[l][c])
          n |= (1 << i), t += a[i][c], h = max(h, a[i][c]);
      dp[n] = min(dp[n], dp[m] + t - h);
    }
  }
  cout << dp[(1 << N) - 1] << endl;
  return 0;
}
