#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
void fastIO() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
char mat[22][22];
int c[22][22];
int tc[22][22];
int cellMask[22][22];
long long dp[1 << 22];
int main() {
  fastIO();
  int n, m, mxCost, lsb, cnt;
  cin >> n >> m;
  for (int i = 0; i < (1 << 22); i++) dp[i] = 1000000000;
  dp[0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> c[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      mxCost = 0;
      for (int k = 0; k < n; k++) {
        if (mat[i][j] == mat[k][j]) {
          mxCost = max(mxCost, c[k][j]);
          cellMask[i][j] |= (1 << k);
          tc[i][j] += c[k][j];
        }
      }
      tc[i][j] -= mxCost;
    }
  }
  for (int msk = 1; msk < (1 << n); msk++) {
    cnt = 0;
    lsb = __builtin_ctz(msk);
    for (int j = 0; j < m; j++) {
      dp[msk] = min(dp[msk], dp[msk ^ (1 << lsb)] + c[lsb][j]);
      dp[msk] = min(dp[msk], dp[msk & (msk ^ cellMask[lsb][j])] + tc[lsb][j]);
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}
