Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;
int n,m,a[16],b[16],p[16];

int main()
{
	cin>>n>>m;
	for (int i = 0; i < n; i++)
		cin>>a[i];
	for (int i = 0; i < m; i++)
		cin>>b[i];
	p[0]=b[0];
	for (int i = 1; i < m; i++)
		p[i]=p[i-1]+b[i];
	int ret=1<<10;
	for (int u = 0; u < 2; u++){
		int count=0;
		for (int i = 0; i < m; i+=2){
			count+=b[i];
		}
		for (int i = 0; i < n; i++){
			if(a[i]==u)count--;
		}
		if(count!=0)continue;

		int t=0,k=0;
		int score=0;
		for (int i = 0; i < m; i+=2){
			for (; k < n; k++){
				if(a[k]==u){
					score+=abs(k-t);
					t++;
					if(t==p[i]){
						k++;
						break;
					}
				}
			}
			if(t!=p[i])
			{
				score = 1<<10;
				break;
			}
			else t+=b[i+1];
		}
		if(t==p[m-1])
			ret=min(score,ret);
	}
	cout<<ret<<endl;

	return 0;
}
