Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	cin >> N >> M;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	vector<int>w(M);
	for (auto &i : w)cin >> i;
	vector<int>dp(1 << N, MOD);
	int a = 0, b = 0;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < w[i]; j++) {
			a <<= 1, b <<= 1;
			if (i & 1)a++;
			else b++;
		}
	}
	dp[a] = 0;
	dp[b] = 0;
	queue<int>Q;
	Q.push(a);
	Q.push(b);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (int i = 1; i < N; i++) {
			if ((cn >> i) % 2 == (cn >> (i - 1)) % 2)continue;
			int nx = cn ^ ((1 << i) | (1 << (i - 1)));
			if (dp[nx] > dp[cn] + 1) {
				dp[nx] = dp[cn] + 1;
				Q.push(nx);
			}
		}
	}
	int ans = 0;
	for (auto i : v) {
		ans <<= 1;
		ans += i;
	}
	cout << dp[ans] << endl;
}
