#include <bits/stdc++.h>
using namespace std;
const int N = 21;
const int M = 1 << 21;
const long long inf = (long long)1e18;
int n, m;
char str[N][N];
long long a[N][N];
long long f[M], g[N][N], h[N][N], mn[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", str[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%I64d", a[i] + j);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= m; k++)
        if (str[i][k] == str[j][k]) g[i][k] |= (1 << (j - 1));
  for (int i = 1; i < (1 << n); i++) f[i] = inf;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int sta = g[i][j];
      long long sum = 0, mx = 0;
      for (int k = 1; k <= n; k++)
        if ((sta >> (k - 1)) & 1) sum += a[k][j], mx = max(mx, a[k][j]);
      h[i][j] = sum - mx;
    }
  for (int i = 1; i <= n; i++) {
    mn[i] = a[i][1];
    for (int j = 1; j <= m; j++) mn[i] = min(mn[i], a[i][j]);
  }
  for (int u = 0, v; u < (1 << n); u++) {
    for (int i = 1; i <= n; i++)
      if (!((u >> (i - 1)) & 1)) {
        v = u | (1 << (i - 1));
        f[v] = min(f[v], f[u] + mn[i]);
        for (int j = 1; j <= m; j++) {
          f[u | g[i][j]] = min(f[u | g[i][j]], f[u] + h[i][j]);
        }
        break;
      }
  }
  printf("%I64d", f[(1 << n) - 1] == inf ? -1 : f[(1 << n) - 1]);
  return 0;
}
