Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

signed main(){
    int N,M;
    cin>>N>>M;
    vint b(N);
    vint p(M);
    rep(i,N)cin>>b[i];
    rep(i,M)cin>>p[i];
    int cnt=count(all(b),0);
    int ans=1<<25;
    rep(i,1<<M){
        int hoge=0;
        rep(j,M)if(i>>j&1)hoge+=p[j];
        for(int j=0;j<M-1;j++){
            int x=i>>j&1;
            int y=i>>(j+1)&1;
            if(x==y)hoge=111111;
        }
        if(cnt!=hoge)continue;
        vint bb(N);
        int cur=0;
        rep(j,M){
            rep(k,p[j]){
                if(i>>j&1)bb[cur+k]=0;
                else bb[cur+k]=1;
            }
            cur+=p[j];
        }
        int foo=0;
        rep(j,N){
            int idx=j;
            while(b[j]!=bb[idx])idx++;
            while(j!=idx){
                swap(bb[idx],bb[idx-1]);
                foo++;
                idx--;
            }
        }
        chmin(ans,foo);
    }
    cout<<ans<<endl;
    return 0;
}