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,s,e) for((i)=(s);(i)<(int)(e);(i)++)

typedef long long ll;

const int INF = 1000000000;
const int N = 15;
const int M = 15;
int n, m;
int b[N], c[N], x[2][N];
int p[M];
bool check[2];
int xi[N], yi[N];

int main() {
	int i, j, k, l, num;
	scanf("%d%d ", &n, &m);
	num = 0;
	for (i=0; i<n; i++) {
		scanf("%d ", b+i);
		c[i] = b[i];
		if (b[i]) num++;
	}
	for (i=0; i<m; i++) scanf("%d ", p+i); 
	for (i=1; i<m; i++) p[i] += p[i-1];

	for (i=0; i<2; i++) {
		int bt = i % 2;
		k = 0;
		int numx = 0;
		for (j=0; j<n; j++) {
			if (j == p[k]) {
				bt = (bt+1) % 2;
				k++;
			}
			x[i][j] = bt;
			if (bt) numx++;
		}

		check[i] = (num == numx) ? true : false;
	}

/*
	printf("b:");
	for (j=0; j<n; j++)
		printf("%d ", b[j]);
	puts("");
	printf("p:");
	for (j=0; j<m; j++)
		printf("%d ", p[j]);
	puts("");

	for (i=0; i<2; i++) {
		printf("x[%d]:", i);
		for (j=0; j<n; j++) printf("%d ", x[i][j]);
		puts("");
	}
*/

	int res = INF;
	for (i=0; i<2; i++) {
		if (check[i]) {
			int cnt = 0;
			k = l = 0;
			for (j=0; j<n; j++) {
				if (x[i][j]) {
					xi[k] = j;
					k++;
				}
				if (b[j]) {
					yi[l] = j;
					l++;
				}
			}

/*
			printf("num = %d\n", num);

			printf("xi:");
			for (j=0; j<num; j++)
				printf("%d ", xi[j]);
			puts("");
			printf("yi:");
			for (j=0; j<num; j++)
				printf("%d ", yi[j]);
			puts("");
*/

			for (j=0; j<num; j++)
				cnt += abs(xi[j] - yi[j]);

			res = min(res, cnt);
		}
	}

	printf("%d\n", res);

	return 0;
}