Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int a1[n],a2[n],b1[n],b2[n],l[m],c=0;
  r(i,n)cin>>a1[i],a2[i]=a1[i];
  r(i,m)cin>>l[i];
  r(i,n){
    for(int p=0;p<l[c];p++,i++)
      b1[i]=c%2,b2[i]=(c+1)%2;
    c++;i--;
  }
  int pp=0,pp1=0;
  r(i,n)if(a1[i]!=b1[i])pp++;
  r(i,n)if(a1[i]!=b2[i])pp1++;
  if(!pp||!pp1){
    cout<<0<<endl;
    return 0;
  }
  int x1=0,y1=0,z1=0;
  r(i,n)if(a1[i])x1++;
  r(i,n)if(b1[i])y1++;
  r(i,n)if(b2[i])z1++;
  int p1=0,p2=0,c1=0,c2=0,k;
  if(x1==y1)for(int j=0;j<n-1;j++)
    if(a1[j]!=b1[j])
      for(int i=j;i<n;i++)
        if(a1[i]==b1[j]){swap(a1[i],a1[j]),p1+=i-j,c1++;break;}
  if(x1==z1)for(int j=0;j<n-1;j++)
    if(a2[j]!=b2[j])
      for(int i=j;i<n;i++)
        if(a2[i]==b2[j]){swap(a2[i],a2[j]),p2+=i-j,c2++;break;}
  if(c1&&c2)k=min(p1,p2);
  else if(c1)k=p1;
  else k=p2;
  cout<<k<<endl;
}