Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int main(){
	int n, m;
	int ans = 100000000;
	cin >> n >> m;
	int a[20], b[20];
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) cin >> b[i];
	for(int u = 0; u < 2; u++){
		int c[20];
		int tmp = 0, pos = 0;
		for(int i = 0; i < m; i++){
			int x = (i+u)%2;
			for(int j = 0; j < b[i]; j++){
				c[pos] = x;
				pos++;
			}
		}
		int A = 0, C = 0;
		for(int i = 0; i < n; i++){
			A += a[i];
			C += c[i];
		}
		if(A != C) continue;
		for(int i = 0; i < n; i++){
			if(a[i] == 0) continue;
			for(int j = 0; j < n; j++){
				if(c[j] == 0) continue;
				tmp += abs(i-j);
				c[j] = 0;
				break;
			}
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
}