#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
string str[maxn];
int a[maxn][maxn], c[maxn][maxn], mask[maxn][maxn];
long long dp[1 << 20];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int msk = 0, tot = 0, big = 0;
      for (int k = 0; k < n; k++) {
        if (str[i][j] == str[k][j]) {
          msk |= (1 << k);
          tot += a[k][j];
          big = max(big, a[k][j]);
        }
      }
      mask[i][j] = msk;
      c[i][j] = tot - big;
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[0] = 0LL;
  for (int i = 1; i < (1 << n); i++) {
    int lowbit;
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        lowbit = j;
        break;
      }
    }
    for (int j = 0; j < m; j++) {
      dp[i] = min(dp[i], dp[i & (i ^ mask[lowbit][j])] + c[lowbit][j]);
      dp[i] = min(dp[i], dp[i ^ (1 << lowbit)] + a[lowbit][j]);
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}
