Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<iostream>
#include<list>
#include<algorithm>
#include <utility>
#include<stdio.h>
#include<climits>

using namespace std;

int main(void){
    int n,m;
    int b[15]={},q[15]={};
    int i,j,k,a[2] = {},s0 = 0,s1 = 0;
    cin >> n >> m;
    for(i = 0;i < n;i++){
        cin >> b[i];
        if(b[i]) s1++;
    }
    for(i = 0,k = 0;i < m;i++){
        cin >> j;
        k += j;
        for(;j > 0;j--){
            q[k-j] = i%2;
            if(q[k-j]) s0++;
        }
    }
    if(s0 == s1){
        for(i = 0,j = 0;i < n;i++){
            if(b[i]){
                while(!q[j]) j++;
                a[0] += abs(i-j);
                j++;
            }
        }
    }else a[0] = INT_MAX;
    if(n-s1 == s0){
        for(i = 0,j = 0;i < n;i++){
            if(b[i]){
                while(q[j]) j++;
                a[1] += abs(i-j);
                j++;
            }
        }
    }else a[1] = INT_MAX;
    cout << min(a[0],a[1]) << endl;
}