Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()

int solve(vi b, vi p){
    if(accumulate(all(b),0) != accumulate(all(p),0)) return 1000;

    int cost=0,n=b.size();
    rep(i,n){
        int j;
        for(j=i; p[i]!=b[j] and j<n ;j++);
        cost+=j-i;
        swap(b[i],b[j]);
    }
    return cost;
}

int main(){
    int n,m;
    cin>>n>>m;
    
    vi b(n),p,cp;
    for(auto &&i:b) cin>>i;
    rep(i,m){
        int t; cin>>t;
        rep(j,t) p.push_back(i%2);
    }
    
    int ans=1000;
    ans=min(ans,solve(b,p));
    for(auto &&i:p) i^=1;
    ans=min(ans,solve(b,p));
    
    cout<<ans<<endl;
	return 0;
}


