#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void amax(X& x, const Y& y) {
  if (x < y) x = y;
}
template <class X, class Y>
void amin(X& x, const Y& y) {
  if (x > y) x = y;
}
const int INF = 1e9 + 10;
const long long INFL = (long long)1e18 + 10;
const int MAX = 20;
int n, m;
string s[MAX];
int a[MAX][MAX];
int b[MAX][MAX], sum[MAX][MAX];
int dp[1 << MAX];
int onbit(int i, int ms) { return ms | (1 << i); }
int offbit(int i, int ms) { return ms & ~(1 << i); }
void process() {
  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 mx = 0;
      for (int k = 0; k < n; k++)
        if (s[i][j] == s[k][j]) {
          b[i][j] |= (1 << k);
          sum[i][j] += a[k][j];
          amax(mx, a[k][j]);
        }
      sum[i][j] -= mx;
    }
  for (int ms = 1; ms < (1 << n); ms++) {
    dp[ms] = INF;
    int x = __builtin_ctz(ms);
    for (int i = 0; i < m; i++) {
      amin(dp[ms], dp[offbit(x, ms)] + a[x][i]);
      int same = b[x][i] & ms;
      amin(dp[ms], dp[ms ^ same] + sum[x][i]);
    }
  }
  cout << dp[(1 << n) - 1];
}
int main() {
  ios_base::sync_with_stdio(false);
  process();
}
