Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }


int main()
{
    using namespace std;

    int n, m;
    cin >> n >> m;

    vec<int> b(n), target(n);
    vec<int> p(m);
    
    for (auto& e : b)
        cin >> e;

    for (int i = 0, current = 0, index = 0; i < m; ++i)
    {
        int in;
        cin >> in;

        for (int i = 0; i < in; ++i)
        {
            target[index + i] = current;
        }
        index += in;

        current ^= 1;
    }

    vec<int> posB, posT, posT_;

    for (int i = 0; i < n; ++i)
    {
        if (b[i] == 1)
            posB.push_back(i);
        if (target[i] == 1)
            posT.push_back(i);
        else
            posT_.push_back(i);
    }

    while (posB.size() < n)
    {
        posB.push_back(1000000);
    }

    while (posT.size() < posB.size())
    {
        posT.push_back(1000000);
    }
    while (posT_.size() < posB.size())
    {
        posT_.push_back(1000000);
    }

    int ans1{}, ans2{};

    for (int i = 0; i < posB.size(); ++i)
    {
        ans1 += abs(posB[i] - posT[i]);
        ans2 += abs(posB[i] - posT_[i]);
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}
