Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int solve(int bit1,int bit2,int n){
	vector<int> done(65536,1e9);
	queue<int> Q;
	Q.push(bit1);
	done[bit1] = 0;
	while( Q.size() ){
		int q = Q.front(); Q.pop();
		for(int i = 1 ; i < n ; i++){
			if( (q >> (i-1) & 3) == 0 || (q >> (i-1) & 3) == 3 ) continue;
			int nex = q^(3 << (i-1));
			if( done[nex] == 1e9 ){
				done[nex] = done[q] + 1;
				Q.push(nex);
			}
		}
	}
	return done[bit2];
}
int main(){
	int n,m;
	cin >> n >> m;
	int a = 0;
	for(int i = 0 ; i < n ; i++){
		int t; cin >> t;
		a = 2*a + t;
	}
	int b = 0;
	
	int l = 0;
	for(int i = 0 ; i < m ; i++){
		int t; cin >> t;
		while(t--) b = b * 2 + (i&1);
	}
	cout << min( solve(a,b,n), solve(a,b^((1<<n)-1),n) ) << endl;
}