Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int d[1<<15],inf=1e8;
int main(){
	int N,M;
	cin>>N>>M;
	int s=0;
	rep(i,N){
		int a;
		cin>>a;
		if(a) s+=(1<<i);
	}
	int x=0,y=0;
	vector<int> vc;
	rep(i,M){
		int p;
		cin>>p;
		rep(j,p) vc.pb(i%2);
	}
	rep(i,N){
		if(vc[i]) x+=(1<<i);
		else y+=(1<<i);
	}
	queue<int> que;
	que.push(s);
	rep(i,1<<N) d[i]=inf;
	d[s]=0;
	while(!que.empty()){
		int q=que.front();
		que.pop();
		int a[15]={};
		rep(j,N) a[j]=(q>>j)&1;
		rep(j,N-1){
			if(a[j]==a[j+1]) continue;
			int nt=q;
			if(a[j]) nt+=(1<<(j+1))-(1<<j);
			else nt+=(1<<j)-(1<<(j+1));
			if(d[nt]==inf){
				que.push(nt);
				d[nt]=d[q]+1;
			}
		}
	}
	cout<<min(d[x],d[y])<<endl;
}