Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)



int main(){
	int n,m;
	cin>>n>>m;
	
	vector<int> a;
	vector<int> b;
	vector<int> c;
	
	rep(i,n){
		int t;
		cin>>t;
		if(t==1)a.push_back(i);
	}
	
	int v = 1;
	int cnt = 0;
	
	rep(i,m){
		int t;
		cin>>t;
		
		rep(j,t){
			if(v==1)b.push_back(cnt+j);
			else c.push_back(cnt+j);
		}
		cnt+=t;
		v=(v+1)%2;
	}
	
	const int INF = 1000000000;
	int ans = INF;
	
	if(a.size()==b.size()){
		ans = 0;
		rep(i,a.size()){
			ans += abs(a[i]-b[i]);
		}
	}
	
	
	
	int ans2 = INF;
	
	if(a.size()==c.size()){
		ans2=0;
		rep(i,a.size()){
			ans2 += abs(a[i]-c[i]);
		}
	}
	
	printf("%d\n",min(ans,ans2));
	
	
	
}