Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;
int a1[20], a2[20], b[20], z[20], o[20];
int main(){
	int n,m;
	cin>>n>>m;
	int zero=0, one=0;
	for(int i=1;i<=n;i++){
		cin>>a1[i];
		a2[i]=a1[i];
		if(!a1[i]) zero++;
		else one++;
	}

	bool f=0;
	int one1=0, zero1=0;
	int one2=0, zero2=0;
	for(int i=1, k=1;i<=m;i++){
		cin>>b[i];
		if(f) one2+=b[i], zero1+=b[i];
		else one1+=b[i], zero2+=b[i];
		for(int j=1;j<=b[i];j++){
			z[k]=f;
			o[k]=!f;
			k++;
		}
		f=!f;
	}

	int cnt1=0, cnt2=0;
	for(int i=1;i<=n;i++){
		if(a1[i]!=z[i]){
			for(int j=i+1;j<=n;j++){
				if(z[i]==a1[j]){
					swap(a1[i], a1[j]);
					cnt1+=(j-i);
					break;
				}
			}
		}
	}

	for(int i=1;i<=n;i++){
		if(a2[i]!=o[i]){
			for(int j=i+1;j<=n;j++){
				if(o[i]==a2[j]){
					swap(a2[i], a2[j]);
					cnt2+=(j-i);
					break;
				}
			}
		}
	}

	/*cout<<one1<<" "<<one2<<" "<<zero1<<" "<<zero2<<endl;
	cout<<one<<" "<<zero<<endl;*/
	if(one1==one2 && zero1==zero2) cout<<min(cnt1, cnt2)<<endl;
	else if(one1==one && zero1==zero) cout<<cnt2<<endl;
	else cout<<cnt1<<endl;
	return 0;
}
