#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m, dp[1 << 20], a[20][20];
string s[20];
vector<pair<int, int> > v[20];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  vector<pair<int, int> > c[26];
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < 26; ++i) c[i].clear();
    for (int i = 0; i < n; ++i) {
      c[s[i][j] - 'a'].push_back(make_pair(a[i][j], i));
      v[j].push_back(make_pair(1 << i, a[i][j]));
    }
    for (int i = 0; i < 26; ++i) sort(c[i].begin(), c[i].end());
    for (int i = 0; i < 26; ++i) {
      if (c[i].empty()) continue;
      int mask = 0, cost = 0;
      for (int k = 0; k < c[i].size() - 1; ++k) {
        cost += c[i][k].first;
      }
      for (int k = 0; k < c[i].size(); ++k) {
        mask += 1 << c[i][k].second;
      }
      v[j].push_back(make_pair(mask, cost));
    }
  }
  memset(dp, 63, sizeof(dp));
  dp[0] = 0;
  for (register int j = 1; j <= m; ++j) {
    for (int mask = 0; mask < 1 << n; ++mask) {
      for (auto it : v[j - 1]) {
        dp[mask | (it.first)] =
            min(dp[mask | (it.first)], dp[mask] + it.second);
      }
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}
