#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void err() { cout << endl; }
template <template <typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) {
  for (auto x : a) cout << x << ' ';
  err(args...);
}
template <typename T, typename... Args>
void err(T a, Args... args) {
  cout << a << ' ';
  err(args...);
}
const int N = 21, INF = 1E9;
char s[N][N];
int n, m, f[1 << N], a[N][N], b[N][N], p[N][N], good[N][N];
int dfs(int u) {
  if (u == 0) return 0;
  if (f[u] != -1) return f[u];
  int &ret = f[u] = INF;
  int x = __builtin_ffs(u) - 1;
  ;
  for (decay<decltype(m)>::type i = (0), _i = (m); i < _i; ++i) {
    ret = min(ret, dfs(u & ~(1 << x)) + a[x][i]);
    ret = min(ret, dfs(u & ~p[x][i]) + b[x][i]);
  };
  return ret;
}
int main() {
  cin >> n >> m;
  for (decay<decltype(n)>::type i = (0), _i = (n); i < _i; ++i)
    scanf("%s", s[i]);
  for (decay<decltype(n)>::type i = (0), _i = (n); i < _i; ++i)
    for (decay<decltype(m)>::type j = (0), _j = (m); j < _j; ++j)
      cin >> a[i][j];
  for (decay<decltype(n)>::type i = (0), _i = (n); i < _i; ++i)
    for (decay<decltype(m)>::type j = (0), _j = (m); j < _j; ++j) {
      int sum = 0, mi = 0, count = 0;
      for (decay<decltype(n)>::type k = (0), _k = (n); k < _k; ++k) {
        if (s[i][j] == s[k][j]) {
          count++;
          sum += a[k][j];
          p[i][j] |= (1 << k);
          mi = max(mi, a[k][j]);
        }
      }
      if (count == 1) good[i][j] = 1;
      b[i][j] = sum - mi;
      ;
    }
  fill(f, f + (1 << n), -1);
  cout << dfs((1 << n) - 1) << endl;
}
