Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int solve(vector<int> a, vector<int> b) {
	int ret = 0;
	rep(i, 0, a.size()) {
		if (a[i] == b[i])continue;
		auto it = find(a.begin() + i, a.end(), b[i]);
		swap(*it, a[i]);
		ret += it - a.begin() - i;
	}
	dumpc(a);
	dumpc(b);
	return ret;
}

signed main() {
	int N, M; cin >> N >> M;
	vector<int> a(N), b(M + 1, 0);
	rep(i, 0, N)cin >> a[i];
	rep(i, 0, M)cin >> b[i];
	int o = 0, e = 0;
	for (int i = 0; i < M; i += 2) {
		o += b[i];
		e += b[i + 1];
	}
	vector<int> c;
	int c1 = accumulate(all(a), 0);
	if (o == e) {
		for (int i = 0; i < M; i += 2) {
			rep(j, 0, b[i])c.emplace_back(1);
			rep(j, 0, b[i + 1])c.emplace_back(0);
		}
		int ans = solve(a, c);
		c.clear();
		for (int i = 0; i < M; i += 2) {
			rep(j, 0, b[i])c.emplace_back(0);
			rep(j, 0, b[i + 1])c.emplace_back(1);
		}
		chmin(ans, solve(a, c));
		cout << ans << endl;
	}
	else {
		if (c1 == o) {
			for (int i = 0; i < M; i += 2) {
				rep(j, 0, b[i])c.emplace_back(1);
				rep(j, 0, b[i + 1])c.emplace_back(0);
			}
			cout << solve(a, c) << endl;
		}
		else {
			for (int i = 0; i < M; i += 2) {
				rep(j, 0, b[i])c.emplace_back(0);
				rep(j, 0, b[i + 1])c.emplace_back(1);
			}
			cout << solve(a, c) << endl;
		}
	}
	return 0;
}