Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int find(int a, vector<int> b, int i){
    for(int j = i; j <= INF; j++){
        if(b[j] == a) return j;
    }
    return INF;
}

bool check(int a[15], vector<int> b, int n){
    int A = 0, B = 0;
    rep(i,n){
        if(a[i] == 1) A++;
        if(b[i] == 1) B++;
    }
    return (A != B);
}

int countSwap(int a[15], vector<int> b, int n){
    if(check(a, b, n)) return INF;

    int ret = 0;
    rep(i,n){
        if(a[i] != b[i]){
            int p = find(a[i], b, i);
            ret += p - i;

            int temp = b[i];
            b[i] = b[p];
            b[p] = temp;
        }
    }
    return ret;
}

int main(){
    int n, m;
    int b[15], p[15];

    cin >> n >> m;
    rep(i,n) cin >> b[i];
    rep(i,m) cin >> p[i];

    vector<int> v0;
    vector<int> v1;

    int temp = 1;
    rep(i,m){
        rep(j,p[i]){
            v0.emplace_back((temp + 1) % 2);
            v1.emplace_back(temp);
        }
        if(temp == 1) temp = 0;
        else temp = 1;
    }
    cout << min(countSwap(b, v0, n), countSwap(b, v1, n)) << endl;
}