Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int N,tmp;

int calc(int base[],int next[]){
	int count = 0;

	 for(int match_point = 0; match_point <= N-1; match_point++){
		 if(base[match_point] != next[match_point]){
			for(tmp = match_point+1; tmp <= N; tmp++){
				if(base[tmp] == next[match_point])break;
			}
			for(int i = tmp; i >= match_point+1; i--){
				swap(base[i],base[i-1]);
				count++;
			}
		 }
	 }

	 return count;
}

 int main(){

	 int M,num[2] = {0,0},index_next = 0;
	 scanf("%d %d",&N,&M);

	 int* base = new int[N];
	 int* next = new int[N];

	 for(int i = 0; i < N; i++){
		 scanf("%d",&base[i]);
		 num[base[i]]++;
	 }

	 if(num[0] == num[1]){
		 int* next2 = new int[N];
		 int* base2 = new int[N];

		 for(int i = 0; i < N; i++)base2[i] = base[i];

		 int index_next2 = 0;

		 for(int i = 0; i < M; i++){
			 scanf("%d",&tmp);

			  for(int k = 0; k < tmp; k++){
				 next[index_next++] = 1 - (i%2);
				 next2[index_next2++] = (i%2);
			 }
		 }

		 printf("%d\n",min(calc(base,next),calc(base2,next2)));

	 }else{
		 int* work = new int[M];
		 int gu_num = 0;

		 for(int i = 0; i < M; i++){
			 scanf("%d",&work[i]);
			 if(i%2 == 0)gu_num += work[i];
		 }


		 for(int i = 0; i < M; i++){
			 for(int k = 0; k < work[i]; k++){
				 if(gu_num == num[0]){
					 next[index_next++] = i%2;
				 }else{
					 next[index_next++] = 1-(i%2);
				 }
			 }
		 }

		 printf("%d\n",calc(base,next));
	 }

	return 0;
}