Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int main()
{
	int N, M, b = 0, bc = 0;
	cin >> N >> M;
	for (int i = 0, bit; i < N; i++) {
		cin >> bit;
		if (bit) {
			b += 1 << i;
			bc++;
		}
	}
	vector<int> p(M);
	int o = 0, e = 0, sum = 0, ps = 0;
	for (int i = 0; i < M; i++) {
		cin >> p[i];
		if (i & 1) {
			ps += ((1 << p[i]) - 1) << sum;
			o += p[i];
		}
		else {
			e += p[i];
		}
		sum += p[i];
	}
	int r1 = 100000, r2 = 100000;
	if (bc == o) {
		r1 = 0;
		vector<int> pos(bc);
		for (int i = 0, j = 0; i < N; i++) {
			if (b & (1 << i)) {
				pos[j++] = i;
			}
		}
		for (int i = 0, j = 0; i < N; i++) {
			if (ps & (1 << i)) {
				r1 += abs(pos[j++] - i);
			}
		}
	}
	if (bc == e) {
		r2 = 0;
		ps = (1 << N) - 1 - ps;
		vector<int> pos(bc);
		for (int i = 0, j = 0; i < N; i++) {
			if (b & (1 << i)) {
				pos[j++] = i;
			}
		}
		for (int i = 0, j = 0; i < N; i++) {
			if (ps & (1 << i)) {
				r2 += abs(pos[j++] - i);
			}
		}
	}
	cout << min(r1, r2) << endl;
	return 0;
}