#include <bits/stdc++.h>
using namespace std;
vector<string> s;
int n, m, a[25][25];
int dp[(1 << 21)];
int go(int msk) {
  if (msk == (1 << n) - 1) return 0;
  if (dp[msk] != -1) return dp[msk];
  int i;
  for (i = 0; i < n && (msk & (1 << i)); i++)
    ;
  int ret = 1e9;
  for (int j = 0; j < m; j++) {
    ret = min(ret, a[i][j] + go(msk | (1 << i)));
    int sum = 0, mx = 0, nmsk = msk;
    for (int k = 0; k < n; k++) {
      if (s[k][j] == s[i][j]) {
        nmsk |= (1 << k);
        sum += a[k][j];
        mx = max(mx, a[k][j]);
      }
    }
    ret = min(ret, sum - mx + go(nmsk));
  }
  return dp[msk] = ret;
}
int main() {
  while (cin >> n >> m) {
    memset(dp, -1, sizeof dp);
    s.resize(n);
    for (int i = 0; i < n; cin >> s[i++])
      ;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cin >> a[i][j];
    cout << go(0) << endl;
  }
  return 0;
}
