Rearranging a Bit String

No attempts yetTime limit1sMemory limit256 MB

Problem

A bit string is a string made only of 0 and 1. You are given one bit string and must turn it into a fixed target string. The only operation you may use is swapping two adjacent bits.

The starting string is given as a plain sequence of bits. The target string is given as a run code instead. A run code lists the lengths of the consecutive blocks of 0s or 1s in the string, in order from the left. For example, the run code of "011100" is "1 3 2". Two strings always share a given run code: one that starts with 0 and one that starts with 1.

Compute the smallest number of operations needed to turn the starting string into the target string.

Input

The first line has two integers NN (1N151 \le N \le 15) and MM (1MN1 \le M \le N). The second line has the NN bits of the starting string, separated by spaces. The third line has the run code of the target string as MM integers, in order.

Every number in the run code is at least 1, and the numbers add up to NN. The given bit string can always be turned into the string that the run code describes.

Output

Print the smallest number of operations needed.

Hint

Take the bit string "100101" and a target run code of "1 3 2". The two possible target strings are "011100" and "100011". Reaching "011100" takes 4 operations, while reaching "100011" takes only 1. The answer is therefore 1.