#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int a[N][N];
char s[N][N];
int rev[1 << N];
int dp[N];
int cost[N][N], st[N][N];
int lowbit(int x) { return x & (-x); }
void update(int &x, int y) {
  if (x == -1)
    x = y;
  else
    x = min(x, y);
}
int main() {
  for (int i = 0; i < N; i++) rev[1 << i] = i;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &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 (s[i][j] == s[k][j]) {
          mx = max(mx, a[k][j]);
          st[i][j] |= (1 << k);
          cost[i][j] += a[k][j];
        }
      }
      cost[i][j] -= mx;
    }
  for (int i = 1; i < (1 << n); i++) dp[i] = 1000000000;
  for (int i = 0; i < (1 << n) - 1; i++) {
    if (dp[i] == -1) continue;
    for (int pos = 0; pos < n; pos++) {
      for (int j = 0; j < m; j++) {
        update(dp[i | st[pos][j]], dp[i] + cost[pos][j]);
        update(dp[i | (1 << pos)], dp[i] + a[pos][j]);
      }
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}
