#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  int a[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];
  int c[n][m];
  fill((int*)c, (int*)c + n * m, 0);
  int flag[n][m];
  fill((int*)flag, (int*)flag + n * m, 0);
  for (int i = 0; i < (n); i++) {
    for (int j = 0; j < (m); j++) {
      int ma = 0;
      for (int k = 0; k < (n); k++) {
        if (s[i][j] == s[k][j]) {
          c[i][j] += a[k][j];
          flag[i][j] |= (1 << k);
          ma = max(ma, a[k][j]);
        }
      }
      c[i][j] -= ma;
    }
  }
  int d[1 << n];
  fill(d, d + (1 << n), 1 << 30);
  d[0] = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    if (mask == 0) continue;
    int low = -1;
    for (int i = 0; i < (n); i++)
      if ((mask >> i) & 1) {
        low = i;
        break;
      }
    for (int i = 0; i < (m); i++) {
      d[mask] = min(d[mask], d[mask & (mask ^ flag[low][i])] + c[low][i]);
      d[mask] = min(d[mask], d[mask ^ (1 << low)] + a[low][i]);
    }
  }
  cout << d[(1 << n) - 1] << endl;
}
