Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector< vector<int> > vvi;

int n, m;
int b[15];
int p[15];
int pb[15];

int solve() {
	int res = 0;
	rep(i, n) {
		if(b[i] != pb[i]) {
			for(int j=i+1; j<n; j++) {
				if( b[j] == pb[i] ) {
					res += j - i;
					b[j] = 1 - b[j];
					b[i] = 1 - b[i];
					break;
				}
			}
		}
	}
	return res;
}

void create_pb(int num) {
	int k = 0;
	rep(i, m) {
		rep(j, p[i]) {
			pb[k] = num;
			k++;
		}
		num = 1 - num;
	}
}

int main() {
	cin >> n >> m;
	rep(i, n) cin >> b[i];
	rep(i, m) cin >> p[i];
	int odd=0, even=0, cnt0=0, cnt1=0;
	rep(i, n) {
		if(b[i]) cnt1++;
		else cnt0++;
	}
	rep(i, m) {
		if(i%2) odd += p[i];
		else    even += p[i];
	}
	int mini = 10000;
	if(odd==cnt0 && even==cnt1) {
		create_pb(1);
		int tmp[15];
		rep(i,n) tmp[i] = b[i];
		mini = min(mini, solve());
		rep(i,n) b[i] = tmp[i];
	}
	if(even==cnt0 && odd==cnt1) {
		create_pb(0);
		mini = min(mini, solve());
	}
	cout << mini << endl;
	return 0;
}