#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a, b, i, dp[1 << 22], j, k, n, m, timer = 0, l, r, x, y;
int c[25][25], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0, us[2000201];
string s[100];
vector<int> v, v2;
pair<int, int> d[25][25];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < m; j++) {
      x = 0;
      y = 0;
      a = 0;
      for (k = 1; k <= n; k++) {
        if (s[k][j] == s[i][j]) {
          x += c[k][j];
          a = max(a, c[k][j]);
          y |= (1 << (k - 1));
        }
      }
      d[i][j] = make_pair(x - a, y);
    }
  }
  for (k = 0; k < (1 << n); k++) {
    dp[k] = INF;
  }
  dp[0] = 0;
  for (k = 0; k < (1 << n); k++) {
    a = -1;
    if (k == 0) continue;
    for (i = 0; i < n; i++) {
      if ((k & (1 << i))) {
        a = i;
        break;
      }
    }
    for (i = 0; i < m; i++) {
      dp[k] =
          min(dp[k], dp[(k & (k ^ d[a + 1][i].second))] + d[a + 1][i].first);
      dp[k] = min(dp[k], dp[(k ^ (1 << a))] + c[a + 1][i]);
    }
  }
  cout << dp[k - 1] << endl;
  return 0;
}
