Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


void solve() {
	int n, m; scanf("%d %d", &n, &m);
	vector<int> b(n); for (int i = 0; i < n; i++) scanf("%d", &b[i]);
	vector<int> p(m); for (int i = 0; i < m; i++) scanf("%d", &p[i]);
	vector<ll> d((1 << n), INF);
	ll ini = 0;
	for (int i = 0; i < n; i++) {
		if (b[i] == 1) ini |= (1 << i);
	}
	d[ini] = 0;
	queue<ll> q; q.push(ini);
	while (!q.empty()) {
		ll cur = q.front();
		q.pop();
		for (int i = 0; i < n - 1; i++) {
			if ((cur >> i & 1) != (cur >> (i + 1) & 1)) {
				ll next = cur;
				next ^= (1 << i);
				next ^= (1 << (i + 1));
				if (d[next] != INF) continue;
				d[next] = d[cur] + 1;
				q.push(next);
			}
		}
	}
	vector<int> c1, c2;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < p[i]; j++) {
			c1.push_back(i % 2 == 0);
			c2.push_back(i % 2 == 1);
		}
	}
	ll t1 = 0, t2 = 0;
	for (int i = 0; i < n; i++) {
		if (c1[i] == 1) t1 |= (1 << i);
		if (c2[i] == 1) t2 |= (1 << i);
	}
	cout << min(d[t1], d[t2]) << endl;
}

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

	int kkt = 1;
	while (kkt--) {
		solve();
	}
	return 0;
}
