B. Light
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Xiao Ming installed $$$n$$$ lights in his new home but forgot to install switches. So he hired $$$m$$$ electricians to install switches for him. These $$$m$$$ electricians are all novices who came to practice switch installation at Xiao Ming's home, so they don't charge for their work.

The electricians arrive and work one by one. When the $$$i$$$-th electrician arrives, he brings a switch and selects $$$k$$$ lights $$$a_1,a_2,...,a_k$$$ from the $$$n$$$ lights to connect them together. Each time this switch is pressed, every one of these $$$k$$$ lights will toggle its state (on becomes off, off becomes on).

Since these novice electricians are here to practice, the set of lights they connect must satisfy the following condition: $$$\mathbf{At\ least\ one\ of\ the \ lights\ connected \ by\ their\ switch\ was \ previously\ connected\ by}$$$$$$\mathbf{\ at\ most\ one\ switch\ before\ theirs.}$$$

After living there for several years, Xiao Ming suddenly discovered that all the switches in his home had broken, but some lights were still on. Due to the passage of time, Xiao Ming could no longer remember the original installation order of the switches, $$$\mathbf{and\ all\ switches\ have\ been\ renumbered}$$$. Now these novice electricians have all become senior electricians, and repairing the $$$i$$$-th switch costs $$$c_i$$$ yuan.

Xiao Ming wants to know the minimum amount of money needed to repair the switches so that he can now turn off all the lights.

Input

The first line contains $$$n,m$$$.

The next line contains a binary string of length $$$n$$$, where '1' in the $$$i$$$-th position means the $$$i$$$-th light is currently on, and '0' means it's off.

The following line contains $$$m$$$ integers $$$c_i$$$, representing the cost to repair each switch.

The next $$$m$$$ lines each contain a binary string of length $$$n$$$, where '1' in the $$$i$$$-th position ($$$1\leq i\leq n$$$) means this switch is connected to the $$$i$$$-th light, and '0' means it's not.

$$$3\leq n,m\leq 60,1\leq c_i\leq 10^5,m\leq 2n$$$.

Output

If there's a solution, output an integer representing the answer; otherwise, output $$$-1$$$.

Examples
Input
4 4
1111
10 5 2 1
1110
1100
0010
0001
Output
8
Input
4 5
1101
10 5 2 1 5
1010
0110
0111
1110
0010
Output
12