#include <bits/stdc++.h>
using namespace std;
template <class T>
string ToString(T t) {
  stringstream s;
  s << t;
  return s.str();
}
template <class T>
void ToOther(T &t, string a) {
  stringstream s(a);
  s >> t;
}
int n, m;
string a[22];
int c1[22][22];
int c2[22][22];
int c2_st[22][22];
int d[22][1 << 20];
void ckmin(int &x, int y) { x = min(x, y); }
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> c1[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c2_st[i][j] |= (1 << i);
      for (int k = 0; k < n; k++)
        if (i != k && a[i][j] == a[k][j]) {
          c2[i][j] += c1[k][j];
          c2_st[i][j] |= (1 << k);
        }
    }
  }
  memset(d, 63, sizeof(d));
  int M = d[0][0];
  int start = 0;
  for (int k = 0; k < m; k++) {
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++)
        if (a[i][k] == a[j][k]) cnt++;
      if (cnt == 1) start |= (1 << i);
    }
  }
  d[0][start] = 0;
  for (int k = 0; k < n; k++) {
    for (int st = 0; st < (1 << n); st++) {
      ckmin(d[k + 1][st], d[k][st]);
      if (!(st >> k & 1)) {
        if (d[k][st] == M) continue;
        for (int pos = 0; pos < m; pos++) {
          ckmin(d[k + 1][st | (1 << k)], c1[k][pos] + d[k][st]);
          int temp = c2[k][pos] + d[k][st];
          ckmin(d[k + 1][st | c2_st[k][pos]], c2[k][pos] + d[k][st]);
        }
      }
    }
  }
  int r = d[n][(1 << n) - 1];
  if (r == M) r = -1;
  cout << r << endl;
}
