Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=a;i<b;++i)

int N, M, b[15], p[15], p1[15], p2[15];

void solve() {
	int ii = 0, v = 0;
	for_(i,0,M) {
		for_(j,0,p[i]) p1[ii] = v, p2[ii++] = 1 - v;
		v = 1 - v;
	}
	
	int cnt = 0, cnt1 = 0, cnt2 = 0;
	for_(i,0,N) cnt += b[i], cnt1 += p1[i], cnt2 += p2[i];
	bool f1 = cnt == cnt1, f2 = cnt == cnt2;	
	
	int ans1 = 0, ans2 = 0, j1 = 0, j2 = 0;
	for_(i,0,N) {
		if (b[i]) {
			if (f1) {
				while (!p1[j1]) ++j1;
				ans1 += abs(j1 - i);
			}
			if (f2) {
				while (!p2[j2]) ++j2;
				ans2 += abs(j2 - i);
			}
			++j1, ++j2;
		}
	}
	
	cout << min(f1 ? ans1 : 100, f2 ? ans2 : 100) << endl;
}

int main() {
	cin >> N >> M;
	for_(i,0,N) cin >> b[i];
	for_(i,0,M) cin >> p[i];
	solve();
	return 0;
}