#include <bits/stdc++.h>
using namespace std;
const int N = 26, MOD = 1e9 + 7;
int a[N][N], tmp[N], mx[N], sum[N], dp[1 << (N - 6)];
string s[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(dp, 63, sizeof(dp));
  dp[0] = 0;
  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];
      dp[(1 << i)] = min(dp[(1 << i)], a[i][j]);
      for (int msk = 0; msk < (1 << n); msk++)
        dp[msk | (1 << i)] = min(dp[msk | (1 << i)], a[i][j] + dp[msk]);
    }
  for (int j = 0; j < m; j++) {
    memset(tmp, 0, sizeof(tmp));
    memset(sum, 0, sizeof(sum));
    memset(mx, 0, sizeof(mx));
    for (int i = 0; i < n; i++) {
      tmp[s[i][j] - 'a'] |= (1 << i);
      sum[s[i][j] - 'a'] += a[i][j];
      mx[s[i][j] - 'a'] = max(mx[s[i][j] - 'a'], a[i][j]);
    }
    for (int i = 0; i < 26; i++) {
      if (!tmp[i]) continue;
      int S = sum[i] - mx[i];
      for (int msk = 0; msk < (1 << n); msk++)
        dp[msk | tmp[i]] = min(dp[msk | tmp[i]], S + dp[msk]);
    }
  }
  cout << dp[(1 << n) - 1];
  return 0;
}
