#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
const long long N = 2e6 + 10;
const long long INF = 1LL << 60;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (long long i = 0; i < static_cast<long long>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
vector<vector<long long>> cost(25, vector<long long>(25, 0));
string s[25];
long long n, m;
long long c[25][25];
long long sv[25][25];
long long dp[N];
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> cost[i][j];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      long long mx = 0;
      for (long long k = 0; k < n; k++) {
        if (s[i][j] == s[k][j]) {
          c[i][j] += cost[k][j];
          chmax(mx, cost[k][j]);
          sv[i][j] |= (1 << k);
        }
      }
      c[i][j] -= mx;
    }
  }
  for (long long i = 0; i < (1 << n); i++) dp[i] = INT_MAX;
  dp[0] = 0;
  for (long long msk = 0; msk < (1 << n); msk++) {
    if (msk == 0) continue;
    long long lowbit = -1;
    for (long long i = 0; i < n; i++) {
      if (msk & (1 << i)) {
        lowbit = i;
        break;
      }
    }
    for (long long i = 0; i < m; i++) {
      chmin(dp[msk], dp[msk & (msk ^ sv[lowbit][i])] + c[lowbit][i]);
      chmin(dp[msk], dp[msk ^ (1 << lowbit)] + cost[lowbit][i]);
    }
  }
  long long msk = (1 << n) - 1;
  cout << dp[msk] << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long Tests = 1;
  while (Tests--) {
    solve();
  }
  return 0;
}
