#include <bits/stdc++.h>
using namespace std;
const long long N = 1000006, INF = 1e18, MOD = 1e9 + 7;
long long n, w, nn, m, a[20][20], b[N], f[20][26], c[20], dp[1 << 20], d[20],
    e[20], x, y, t, u, o, h, ans, Ans = INF;
pair<int, pair<int, int> > p[20];
string second;
vector<string> s;
vector<long long> v[N];
vector<pair<int, int> > q;
int main() {
  cin >> n >> m;
  nn = n;
  for (int i = 0; i < n; i++) {
    cin >> second;
    s.push_back(second);
    for (int j = 0; j < m; j++) f[j][s[i][j] - 'a']++;
  }
  for (int i = 0; i < n; i++) {
    u = 0;
    for (int j = 0; j < m; j++)
      if (f[j][s[i][j] - 'a'] < 2) u = 1;
    if (u) w |= (1 << i);
  }
  for (int i = 0; i < n; i++) {
    b[i] = INF;
    for (int j = 0; j < m; j++) cin >> a[i][j], b[i] = min(a[i][j], b[i]);
  }
  for (int i = 0; i < (1 << n); i++)
    if ((i & w) != i) dp[i] = INF;
  for (int i = 0; i < m; i++) {
    q.clear();
    for (int j = 0; j < n; j++) p[j] = {s[j][i] - 'a', {-a[j][i], j}};
    sort(p, p + n);
    for (int j = 0; j < n; j++) {
      t = x = y = 0;
      x |= (1 << p[j].second.second);
      while (j + 1 < n && p[j + 1].first == p[j].first)
        j++, x |= (1 << p[j].second.second), y -= p[j].second.first, t++;
      if (t) q.push_back({x, y});
    }
    for (int j = 0; j < q.size(); j++)
      for (int r = 0; r < (1 << n); r++)
        dp[r | q[j].first] = min(dp[r | q[j].first], dp[r] + q[j].second);
  }
  for (int r = 0; r < (1 << n); r++) {
    x = r;
    ans = 0;
    o = n;
    while (o--) ans += (x & 1 ^ 1) * b[n - o - 1], x = (x >> 1);
    Ans = min(Ans, ans + dp[r]);
  }
  cout << Ans;
}
