Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int calc(int x, vector<int> b, const vector<int> &p) {
	const int n = b.size();

	int res = 0;
	int index = 0;

	for(const auto &e : p) {
		for(int i = 0; i < e; ++i) {
			int next_index = index;
			while(next_index < n && b[next_index] != x) ++next_index;

			if(next_index == n) return INT_MAX;
			res += next_index - index;
			swap(b[index], b[next_index]);
			++index;
		}

		x ^= 0x1;
	}
	return res;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;

	vector<int> b(n), p(m);
	for(auto &e : b) cin >> e;
	for(auto &e : p) cin >> e;

	cout << min(calc(1, b, p), calc(0, b, p)) << endl;

	return EXIT_SUCCESS;
}