Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int n, m;
int b[15], p[16], g[15];

int calc()
{
	int a[15];
	int res = 0;
	for (int i = 0; i < n; i++) a[i] = b[i];
	for (int i = 0; i < n; i++){
		int q = find(a + i, a + n, g[i]) - a;
		if (q == n) return 1 << 28;
		for (int j = q; j > i; j--){
			swap(a[j], a[j - 1]);
			res++;
		}
	}
	return res;
}

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d", b + i);
	for (int i = 0; i < m; i++){
		scanf("%d", p + i + 1);
		p[i + 1] += p[i];
	}
	
	for (int i = 0; i < m; i++){
		for (int j = p[i]; j < p[i + 1]; j++){
			g[j] = i & 1;
		}
	}
	
	int res = calc();
	for (int i = 0; i < n; i++) g[i] ^= 1;
	res = min(res, calc());
	
	printf("%d\n", res);
}