#include <bits/stdc++.h>
using namespace std;
const int N = 25;
const int MX = 1 << 20;
int dp[MX], mx;
int n, m, sta[N][N], cost[N][N], a[N][N];
char s[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s + i);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cost[i][j] = 0;
      sta[i][j] = 1 << i;
      for (int x = 0; x < n; x++) {
        if (i == x || s[i][j] != s[x][j]) continue;
        sta[i][j] |= 1 << x;
        cost[i][j] += a[x][j];
      }
    }
  mx = 1 << n;
  memset(dp, 0x3F, sizeof(dp));
  dp[0] = 0;
  for (int x = 0; x < mx; x++) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        int y = x | sta[i][j];
        if (x == y) continue;
        dp[y] = min(dp[y], dp[x] + cost[i][j]);
        y = x | (1 << i);
        if (x == y) continue;
        dp[y] = min(dp[y], dp[x] + a[i][j]);
      }
  }
  printf("%d\n", dp[mx - 1]);
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

You have multiset of n strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position i and some letter c of the English alphabet, such that this string is the only string in the multiset that has letter c in position i.

For example, a multiset of strings {"abc", "aba", "adc", "ada"} are not easy to remember. And multiset {"abc", "ada", "ssa"} is easy to remember because: 

  * the first string is the only string that has character c in position 3; 
  * the second string is the only string that has character d in position 2; 
  * the third string is the only string that has character s in position 2. 



You want to change your multiset a little so that it is easy to remember. For aij coins, you can change character in the j-th position of the i-th string into any other lowercase letter of the English alphabet. Find what is the minimum sum you should pay in order to make the multiset of strings easy to remember.

Input

The first line contains two integers n, m (1 ≤ n, m ≤ 20) — the number of strings in the multiset and the length of the strings respectively. Next n lines contain the strings of the multiset, consisting only of lowercase English letters, each string's length is m.

Next n lines contain m integers each, the i-th of them contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 106).

Output

Print a single number — the answer to the problem.

Examples

Input

4 5
abcde
abcde
abcde
abcde
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1


Output

3


Input

4 3
abc
aba
adc
ada
10 10 10
10 1 10
10 10 10
10 1 10


Output

2


Input

3 3
abc
ada
ssa
1 1 1
1 1 1
1 1 1


Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 25;
const int MX = 1 << 20;
int dp[MX], mx;
int n, m, sta[N][N], cost[N][N], a[N][N];
char s[N][N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s + i);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cost[i][j] = 0;
      sta[i][j] = 1 << i;
      for (int x = 0; x < n; x++) {
        if (i == x || s[i][j] != s[x][j]) continue;
        sta[i][j] |= 1 << x;
        cost[i][j] += a[x][j];
      }
    }
  mx = 1 << n;
  memset(dp, 0x3F, sizeof(dp));
  dp[0] = 0;
  for (int x = 0; x < mx; x++) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        int y = x | sta[i][j];
        if (x == y) continue;
        dp[y] = min(dp[y], dp[x] + cost[i][j]);
        y = x | (1 << i);
        if (x == y) continue;
        dp[y] = min(dp[y], dp[x] + a[i][j]);
      }
  }
  printf("%d\n", dp[mx - 1]);
  return 0;
}

```