Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <cstdio>
#include <vector>
using std::vector;

int min(int a, int b){return (a<b)?a:b;}
int abs(int x){return (x>0)?x:-x;}

int N, M;
int count[2];
vector<int> pos[2];
vector<int> am[2];

int main(){
    scanf("%d %d", &N, &M);
    for(int i=1;i<=N;i++){
        int an;
        scanf("%d", &an);
        pos[an].push_back(i);
    }
    int j=1;
    for(int i=1;i<=M;i++){
        int m;
        scanf("%d", &m);
        for(int k=1;k<=m;k++){
            am[(i%2)].push_back(j);
            j++;
        }
    }
    int diff = 100;
    if(pos[0].size()==am[0].size()){
        int tmp = 0;
        for(int i=0;i<pos[0].size();i++){
            tmp += abs( pos[0][i] - am[0][i] );
        }
        diff = min(diff, tmp);
    }
    if(pos[0].size()==am[1].size()){
        int tmp = 0;
        for(int i=0;i<pos[0].size();i++){
            tmp += abs( pos[0][i] - am[1][i] );
        }
        diff = min(diff, tmp);
    }
    printf("%d\n", diff);
    return 0;
}