#include <bits/stdc++.h>
using namespace std;
int a[20][20], cst[20][20], dp[1 << 20], msks[20][20];
char c[20][20];
int main() {
  int n, m;
  cin >> n >> m;
  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++) 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 (c[k][j] == c[i][j]) {
          cst[i][j] += a[k][j];
          mx = max(mx, a[k][j]);
        }
      }
      cst[i][j] -= mx;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++) {
        if (c[i][j] == c[k][j]) msks[i][j] |= (1 << k);
      }
    }
  }
  for (int mask = 1; mask < (1 << n); mask++) {
    int lowst_bit = 0;
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        lowst_bit = i;
        break;
      }
    }
    dp[mask] = 100000000;
    for (int j = 0; j < m; j++) {
      dp[mask] =
          min(dp[mask],
              min(dp[mask ^ (mask & msks[lowst_bit][j])] + cst[lowst_bit][j],
                  dp[mask ^ (1 << lowst_bit)] + a[lowst_bit][j]));
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  cin >> n;
  return 0;
}
