Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 15;
static const int MAX_M = 15;

int N, M;
int b[MAX_N];
int p[MAX_M];
int cnt, cnt2;
int sum, sum2;

int calc(int num){
	int b2[MAX_N];
	int index = 0;
	for(int i = 0; i < M; i++){
		for(int j = 0; j < p[i]; j++){
			b2[index] = (i % 2 + num) % 2;
			index++;
		}
	}
	int res = 0;
	for(int i = 0; i < N; i++){
		if(b[i] != b2[i]){
			int index = -1;
			for(int j = i + 1; j < N; j++){
				if(b2[j] == b[i]){
					index = j;
					break;
				}
			}
			if(index == -1) return 1 << 30;
			for(; index > i; index--){
				swap(b2[index], b2[index - 1]);
				res++;
			}
		}
	}
	return res;
}

int main(){
	scanf("%d %d", &N, &M);
	cnt = 0, cnt2 = 0, sum = 0, sum2 = 0;
	for(int i = 0; i < N; i++){
		scanf("%d", &b[i]);
		if(b[i] == 0) cnt++;
		else cnt2++;
	}
	for(int i = 0; i < M; i++){
		scanf("%d", &p[i]);
		if(i % 2 == 0) sum += p[i];
		else sum2 += p[i];
	}
	printf("%d\n", min(calc(0), calc(1)));
	return 0;
}

