#include <bits/stdc++.h>
using namespace std;
int dp[1 << 20], w[25][25];
string s[25];
pair<int, int> alph[25][26];
int ma[25][26];
int cost[1 << 20];
vector<pair<int, int> > rco;
int main() {
  int n, m;
  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 >> w[i][j];
  }
  fill(cost, cost + (1 << 20), (int)1e9);
  cost[0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      cost[1 << j] = min(cost[1 << j], w[j][i]);
      alph[i][(s[j][i] - 'a')].first |= (1 << j);
      alph[i][(s[j][i] - 'a')].second += w[j][i];
      ma[i][s[j][i] - 'a'] = max(ma[i][s[j][i] - 'a'], w[j][i]);
    }
    for (int j = 0; j < 26; j++) {
      alph[i][j].second -= ma[i][j];
      cost[alph[i][j].first] = min(cost[alph[i][j].first], alph[i][j].second);
    }
  }
  for (int i = 1; i < (1 << 20); i++) {
    if (cost[i] != (int)1e9) rco.push_back(make_pair(i, cost[i]));
  }
  fill(dp, dp + (1 << n), (int)1e9);
  dp[0] = 0;
  for (int i = 0; i < rco.size(); i++) {
    const int mask = rco[i].first, co = rco[i].second;
    for (int j = 0; j < (1 << n); j++) {
      dp[j | mask] = min(dp[j | mask], dp[j] + co);
    }
  }
  cout << dp[(1 << n) - 1];
}
