Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

C. Remembering Strings

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou 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 *a*_{ij} 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 *a*_{i1}, *a*_{i2}, ..., *a*_{im} (0 ≤ *a*_{ij} ≤ 10^{6}).

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

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/12/2018 11:51:25 (d1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|