Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
ld eps = 1e-9;

int main() {
	int N, M; cin >> N >> M;
	vector<int>nums;
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		nums.emplace_back(a);
	}
	const int whitenum = accumulate(nums.begin(), nums.end(), 0);
	vector<int>sizes;
	vector<int>finnums;
	for (int i = 0; i < M; ++i) {
		int a; cin >> a;
		sizes.emplace_back(a);
		for (int j = 0; j < a; ++j) {
			finnums.push_back(i % 2 == 0);
		}
	}
	int firstnum = 0;
	int secondnum = 0;
	{
		for (int i = 0; i < M; i += 2) {
			firstnum += sizes[i];
		}
		secondnum = N - firstnum;
	}
	int ans = 1e8;
	if (firstnum == whitenum) {
		auto it = find(nums.begin(), nums.end(), 1);
		auto jt = find(finnums.begin(), finnums.end(), 1);
		int nans = 0;
		for (int i = 0; i < whitenum; ++i) {
			nans += abs((it - nums.begin()) - (jt - finnums.begin()));
			it = find(next(it), nums.end(), 1);
			jt = find(next(jt), finnums.end(), 1);
		}
		ans = nans;
	}
	if (secondnum == whitenum) {
		auto it = find(nums.begin(), nums.end(), 1);
		auto jt = find(finnums.begin(), finnums.end(), 0);
		int nans = 0;
		for (int i = 0; i < whitenum; ++i) {
			nans += abs((it - nums.begin()) - (jt - finnums.begin()));
			it = find(next(it), nums.end(), 1);
			jt = find(next(jt), finnums.end(), 0);
		}
		ans =min(ans, nans);
	}
	cout << ans << endl;
	return 0;
}