Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

int solve(int N, int b, int p) {
    if (__builtin_popcount(b) != __builtin_popcount(p)) return 1 << 24;
    int swp = 0;
    for (int i = 0; i < N && b != p; ++i) {
        if ((b >> i & 1) == (p >> i & 1)) continue;
        for (int j = i + 1; j < N; ++j) {
            if ((p >> i & 1) == (p >> j & 1)) continue;
            swp += j - i;
            p ^= 1 << i | 1 << j;
            break;
        }
    }
    return swp;
}

int main() {
    int N, M; cin >> N >> M;
    int b = 0, p = 0;
    rep(i, N) {
        int x; cin >> x;
        b <<= 1;
        b |= x;
    }
    rep(i, M) {
        int l = 0; cin >> l;
        p <<= l;
        if (i & 1) p |= (1 << l) - 1;
    }
    cout << min(solve(N, b, p), solve(N, b, p ^ ((1 << N) - 1))) << endl;
}