Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;

int numSwap(vector<int> a,vector<int> b){
	int ret = 0;
	int x = 0;
	for(int i=0;i<a.size();i++){
		if(a[i]){
			for(int j=x;j<a.size();j++){
				if(b[j]){
					ret += abs(i-j);
					x = j+1;
					break;
				}
			}
		}
	}
	return ret;
}

int main(void){
	int N,M;
	cin >> N >> M;
	vector<int> b(N),p(M);
	int cnt = 0;
	for(int i=0;i<N;i++){
		cin >> b[i];
		if(b[i])cnt++;
	}
	for(int i=0;i<M;i++)
		cin >> p[i];

	vector<int> a1,a2;
	bool bit = 1;
	int cnt1=0,cnt2=0;
	for(int i=0;i<M;i++){
		for(int j=0;j<p[i];j++){
			a1.push_back(bit);
			cnt1 += bit;
			a2.push_back(!bit);
			cnt2 += (!bit);
			//cout << !bit << " ";
		}
		bit = !bit;
	}
/*
	for(int i=0;i<a1.size();i++){
		cout << a1[i] << " ";;
	}
	cout << endl;
	for(int i=0;i<a2.size();i++){
		cout << a2[i] << " ";;
	}
	cout << endl;
*/
	if(cnt1 == cnt && cnt2 == cnt){
		cout << min(numSwap(a2,b),numSwap(a1,b)) << endl;
	}else if(cnt1 == cnt){
		cout << numSwap(a1,b) << endl;
	}else{
		cout << numSwap(a2,b) << endl;
	}

	return 0;
}