#include <bits/stdc++.h>
using namespace std;
inline long long getint() {
  long long _x = 0, _tmp = 1;
  char _tc = getchar();
  while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
  if (_tc == '-') _tc = getchar(), _tmp = -1;
  while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
  return _x * _tmp;
}
long long mypow(long long _a, long long _x, long long _mod) {
  if (_x == 0) return 1ll;
  long long _tmp = mypow(_a, _x / 2, _mod);
  _tmp = (_tmp * _tmp) % _mod;
  if (_x & 1) _tmp = (_tmp * _a) % _mod;
  return _tmp;
}
inline long long add(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x + _y;
  if (_ >= _mod) _ -= _mod;
  return _;
}
inline long long sub(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x - _y;
  if (_ < 0) _ += _mod;
  return _;
}
inline long long mul(long long _x, long long _y,
                     long long _mod = 1000000007ll) {
  long long _ = _x * _y;
  if (_ >= _mod) _ %= _mod;
  return _;
}
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int __ = 1, cs;
void build() {}
int n, m;
char c[22][22];
int a[22][22];
int b[22][22];
int bm[22][22];
void init() {
  n = getint();
  m = getint();
  for (int i = 0; i < n; i++) scanf("%s", c[i] + 1);
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = getint();
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= m; j++) {
      int tcst = 0, tmx = 0, tmsk = 0;
      for (int k = 0; k < n; k++)
        if (c[i][j] == c[k][j]) {
          tmsk |= (1 << k);
          tcst += a[k][j];
          tmx = max(tmx, a[k][j]);
        }
      b[i][j] = tcst - tmx;
      bm[i][j] = tmsk;
    }
}
int dp[1 << 22];
void solve() {
  for (int i = 1; i < (1 << n); i++) {
    int lb = round(log2(i & -i));
    dp[i] = 1023456789ll;
    for (int j = 1; j <= m; j++) {
      dp[i] = min(dp[i], dp[i & (~bm[lb][j])] + b[lb][j]);
      dp[i] = min(dp[i], dp[i ^ (1 << lb)] + a[lb][j]);
    }
  }
  printf("%d\n", dp[(1 << n) - 1]);
}
int main() {
  build();
  while (__--) {
    init();
    solve();
  }
}
