Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int f(vector<int> a, vector<int> b) {
	vector<int> x[2], y[2];
	for(int i = 0; i < a.size(); ++i) x[a[i]].push_back(i);
	for(int i = 0; i < b.size(); ++i) y[b[i]].push_back(i);
	if(x[0].size() != y[0].size() || x[1].size() != y[1].size()) return INT_MAX;
	int ret = 0;
	for(int i = 0; i < x[0].size(); ++i) ret += abs(x[0][i] - y[0][i]);
	for(int i = 0; i < x[1].size(); ++i) ret += abs(x[1][i] - y[1][i]);
	return (ret >> 1);
}

int main() {
	int n, m; scanf("%d%d", &n, &m);
	vector<int> a(n), b;
	for(auto &v: a) scanf("%d", &v);
	for(int t, j = 0; m-- && scanf("%d", &t); j ^= 1) while(t--) b.push_back(j);
	int ans = f(a, b);
	for(auto &v: a) v ^= 1;
	printf("%d\n", min(ans, f(a, b)));
	return 0;
}