Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int solve(vector<int> a,vector<int> b,int N){
    int c=0;
    for (int i = 0; i < N; i++) {
        if(a[i]==1) c++;
        if(b[i]==1) c--;
    }
    if(c!=0) return INF;

    int t=-1,ret=0;
    for(int i=0;i<N;i++){
        if(a[i]==1){
            for(int j=t+1;j<N;j++){
                if(b[j]==1){
                    t=j;
                    ret+=abs(j-i);
                    break;
                }
            }
        }
    }
    return ret;
}







int main(){
    int N,M;cin >> N >> M;
    vector<int> a(N),b,c; 
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < M; i++) {
        int t;cin >> t;
        for (int j = 0; j < t; j++) {
            b.pb(i%2?1:0);
            c.pb(i%2?0:1);
        }
    }
    cout << min(solve(a,b,N),solve(a,c,N)) << endl;
    return 0;
}

