Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

int calc(vector<int> &from, vector<int> &to)
{
    if (accumulate(from.begin(), from.end(), 0) != accumulate(to.begin(), to.end(), 0))
        return INT_MAX;

    int res = 0, k = 0;
    for (int i = 0; i < (int)from.size(); ++i)
    {
        if (from[i] == 0)
            continue;
        while (to[k] == 0)
            k++;
        res += abs(i - k);
        k++;
    }

    return res;
}

int main()
{
    int N, M;
    cin >> N >> M;

    vector<int> b(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> b[i];
    }

    vector<int> p1(N), p2(N);
    int k = 0, p;
    for (int i = 0; i < M; ++i)
    {
        cin >> p;
        while (p--)
        {
            p1[k] = i % 2;
            p2[k] = (i + 1) % 2;
            k++;
        }
    }
    cout << min(calc(b, p1), calc(b, p2)) << endl;

    return 0;
}
