Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int main() {
    int N, M;
    int b[16], c[16], p[16];
    scanf("%d%d", &N, &M);
    for(int i = 0; i < N; ++i){
        scanf("%d", b + i);
        c[i] = b[i];
    }
    for(int i = 0; i < M; ++i){
        scanf("%d", p + i);
    }
    int ans = 10000000;
    bool success;
    for(int n = 0; n < 2; ++n){
        success = true;
        int d = n, i = 0;
        int n_swap = 0;
        for(int j = 0; j < M; ++j){
            for(int k = 0; k < p[j]; ++k, ++i){
                int l;
                for(l = i; l < N && b[l] != d; ++l);
                if(l < N){
                    n_swap += l - i;
                    swap(b[i], b[l]);
                }else{
                    success = false;
                    break;
                }
            }
            if(!success) break;
            d = 1 - d;
        }
        if(success){
            ans = min(n_swap, ans);
        }
        for(int i = 0; i < N; ++i){
            b[i] = c[i];
        }
    }
    printf("%d\n", ans);
    return 0;
}