#include <bits/stdc++.h>
using namespace std;
constexpr int top = 1 << 20;
int dp[top];
int a[20][20];
pair<int, int> opts[220];
bool ok[20];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s[20];
  int n;
  unsigned m;
  cin >> n >> m;
  if (0 > n || n > 20) {
    cout << "too many strings\n";
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    if (s[i].size() != m) {
      cout << "bad format\n";
      return 0;
    }
    for (unsigned j = 0; j < m; ++j)
      if ('a' > s[i][j] || s[i][j] > 'z') {
        cout << "illegal character\n";
        return 0;
      }
  }
  for (int i = 0; i < n; ++i)
    for (unsigned j = 0; j < m; ++j) cin >> a[i][j];
  int nOpts = 0;
  for (unsigned j = 0; j < m; ++j) {
    int seens[26];
    int last[26];
    for (int c = 0; c < 26; ++c) seens[c] = 0, last[c] = -1;
    for (int i = 0; i < n; ++i) {
      int c = s[i][j] - 'a';
      seens[c] += 1 << i;
      last[c] = i;
    }
    for (int c = 0; c < 26; ++c) {
      int sc = seens[c];
      if (sc) {
        if (sc == (sc & -sc))
          ok[last[c]] = true;
        else {
          int cost = 0;
          int maxc = 0;
          for (int i = 0; i < n; ++i) {
            if (0 == (sc & (1 << i))) continue;
            cost += a[i][j];
            maxc = max(maxc, a[i][j]);
          }
          opts[nOpts++] = pair<int, int>(sc, cost - maxc);
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (ok[i]) continue;
    int minc = (-1u >> 1);
    for (unsigned j = 0; j < m; ++j) minc = min(minc, a[i][j]);
    opts[nOpts++] = pair<int, int>(1 << i, minc);
  }
  int start = 0;
  int last = (1 << n) - 1;
  int lastBit = (1 << (n - 1));
  for (int i = 0; i < n; ++i)
    if (ok[i]) start += 1 << i;
  dp[start] = 1;
  for (int on = 0; on < nOpts; ++on) {
    pair<int, int> copt = opts[on];
    int res = start | copt.first;
    if (dp[res])
      dp[res] = min(dp[res], 1 + copt.second);
    else
      dp[res] = 1 + copt.second;
  }
  for (int cs = lastBit; cs < last; ++cs) {
    int cc = dp[cs];
    if (cc == 0) continue;
    for (int on = 0; on < nOpts; ++on) {
      pair<int, int> copt = opts[on];
      int res = cs | copt.first;
      if (dp[res])
        dp[res] = min(dp[res], cc + copt.second);
      else
        dp[res] = cc + copt.second;
    }
  }
  cout << (dp[last] - 1) << "\n";
  ;
  return 0;
}
