Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define INF 1e9

int solve(bitset<15> b, bitset<15> goal){
    if(b.count() != goal.count())return INF;
    int cnt=0;
    rep(l,14)if(b[l]!=goal[l]){
        int r=l+1;
        while(b[l]==b[r]) r++;
        while(l<r){
            b[r].flip();
            r--;
            b[r].flip();
            cnt++;
        }
    }
    return cnt;
}

int main(void){
    int N,M,p,bit;
    cin>>N>>M;
    bitset<15> b,goal1,goal2;
    rep(i,N) cin>>bit, b[i]=bit;
    int index=0;
    rep(i,M) {
        cin>>p;
        rep(j,p){
            goal1[index] = (i%2==0);
            goal2[index] = (i%2!=0);
            index++;
        }
    }
    cout<<min(solve(b,goal1),solve(b,goal2))<<endl;
    return 0;
}