Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <cstdlib>
#ifndef LIB_REPEAT_HPP
#define LIB_REPEAT_HPP
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#define foreach(it, cont) for (decltype(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
using namespace std;
#define INF (1<<28)
int main() {
    ios_base::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    vector<bool> b(N); repeat (i,N) { int a; cin >> a; b[i] = not not a; }
    vector<int>  p(M); repeat (i,M) cin >> p[i];
    int result = INF;
    repeat (d,2) {
        vector<int> c, q;
        repeat (i,N) if (b[i]) c.push_back(i);
        {
            int i = 0;
            repeat (j,M) {
                repeat (k,p[j]) {
                    if ((j+d) % 2) q.push_back(i);
                    i ++;
                }
            }
        }
        if (c.size() == q.size()) {
            int acc = 0;
            repeat (i, (int)c.size()) {
                acc += labs(c[i] - q[i]);
            }
            result = min(result, acc);
        }
    }
    cout << result << endl;
    return 0;
}