Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define pmod 1000000007
#define maxn 100005
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )

using namespace std;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
int a[1000],b[1000],c[1000],p[1000],r[1000];
int N,m;
int  swap1 (int x[1000], int y[1000]){
int    res=0; int st=1;
    while (st<=N){
        if (x[st]==y[st]) {}//st++;
        else{
            FOR (i,st+1,N){
                if (y[i]==x[st]) {
                    swap(y[i],y[st]);
                    //st++;
                    res+=i-st;
                    break;
                }
            }
        }
        //cout<<x[st]<<y[st]<<endl;
        st++;
    }
    return res;
}
int s1,s0,ss1,ss0;
int main()
{
cin>>N>>m;
FOR (i,1,N){
    cin>>a[i];
    if (a[i]==1) s1++;
else s0++;

}
FOR (i,1,m){
cin>>p[i];
r[i]=r[i-1]+p[i];
}
FOR (i,1,m){
    FOR (j,r[i-1]+1,r[i]){
        b[j]=i%2;c[j]=(i+1)%2;
        if (b[j]==1) ss1++;
        else ss0++;
    }

}
//cout<<s0<<s1<<ss1<<ss0<<endl;
//FOR (i,1,N) cout<<c[i];
int r1=INF; int r2=INF;
if (ss1==s1) r1=swap1(a,b);
if (ss0==s1) r2=swap1(a,c);
//cout<<r1<<endl;
cout<<min (r1,r2)<<endl;
         return 0;
}