#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T first, T second) {
  while (second > 0) {
    first %= second;
    swap(first, second);
  }
  return first;
}
template <class _T>
inline _T sqr(const _T &first) {
  return first * first;
}
template <class _T>
inline string tostr(const _T &a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
template <typename T>
inline void input(T &a) {
  static int ed;
  a = 0;
  while (!isdigit(ed = getchar()) && ed != '-') {
  }
  char neg = 0;
  if (ed == '-') {
    neg = 1;
    ed = getchar();
  }
  while (isdigit(ed)) {
    a = 10 * a + ed - '0';
    ed = getchar();
  }
  if (neg) a = -a;
}
template <typename T = int>
inline T nxt() {
  T res;
  input(res);
  return res;
}
mt19937 generator;
const int N = 3000;
int dist[N][N];
vector<int> g[N];
int n;
void calc(int v) {
  int *d = dist[v];
  memset(d, 0x3f, n * sizeof(int));
  d[v] = 0;
  queue<int> q;
  q.push(v);
  while (!q.empty()) {
    int z = q.front();
    q.pop();
    for (int to : g[z]) {
      if (d[to] > n) {
        d[to] = d[z] + 1;
        q.push(to);
      }
    }
  }
}
int main() {
  int n = nxt();
  int m = nxt();
  string s[n];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  int cost[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cost[i][j] = nxt();
    }
  }
  vector<pair<int, int> > delta;
  for (int i = 0; i < n; ++i) {
    int best = INT_MAX;
    for (int j = 0; j < m; ++j) {
      best = min(best, cost[i][j]);
    }
    delta.push_back({1 << i, best});
  }
  int ids[n];
  for (int j = 0; j < n; ++j) {
    ids[j] = j;
  }
  for (int i = 0; i < m; ++i) {
    sort(ids, ids + n, [&](int u, int v) { return s[u][i] < s[v][i]; });
    int sum[n + 1];
    sum[0] = 0;
    for (int j = 0; j < n; ++j) {
      sum[j + 1] = sum[j] + cost[ids[j]][i];
    }
    for (int j = 0; j < n; ++j) {
      int k = j;
      int mask = 0;
      while (k < n && s[ids[k]][i] == s[ids[j]][i]) {
        mask |= 1 << ids[k];
        ++k;
      }
      int best = INT_MAX;
      for (int l = j; l < k; ++l) {
        best = min(best, sum[k] - sum[j] - cost[ids[l]][i]);
      }
      delta.push_back({mask, best});
      j = k - 1;
    }
  }
  int dp[1 << n];
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i < (1 << n); ++i) {
    for (auto z : delta) {
      dp[i | z.first] = min(dp[i | z.first], dp[i] + z.second);
    }
  }
  cout << dp[(1 << n) - 1] << "\n";
  return 0;
}
