#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int maxn = 2e6 + 100, mxn = 5e5 + 100;
const long double PI = acos(-1.0);
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long power(long long a, long long n) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long power(long long a, long long n, long long mod) {
  long long p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
int n, m;
int dp[maxn], va[25][25], voil[25][25], sv[25][25];
char s[25][25];
vector<int> con;
int po[30];
int main() {
  while (~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", &va[i][j]);
    for (int i = 0; i <= 20; i++) po[i] = (1 << i);
    memset(dp, 0, sizeof dp);
    memset(voil, 0, sizeof voil);
    memset(sv, 0, sizeof sv);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        int mm = 0;
        for (int k = 0; k < n; k++)
          if (s[k][j] == s[i][j]) {
            voil[i][j] += po[k];
            mm = max(mm, va[k][j]);
            sv[i][j] += va[k][j];
          }
        sv[i][j] -= mm;
      }
    for (int i = 1; i < 1 << n; i++) {
      int cur = 0, g = i;
      con.clear();
      while (g % 2 == 0) {
        cur++;
        g = g >> 1;
      }
      g = 1 << cur;
      g = i - g;
      int gg = g;
      int minn = inf;
      for (int j = 0; j < m; j++) {
        minn = min(minn, dp[i & (i ^ voil[cur][j])] + sv[cur][j]);
        minn = min(minn, dp[gg] + va[cur][j]);
      }
      dp[i] = minn;
    }
    cout << dp[(1 << n) - 1] << endl;
  }
  return 0;
}
