Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define ALL(x) begin(x), end(x)
using namespace std;

string deflate_run_length_code(vector<int> const & p, bool initial) {
    string s;
    for (int p_i : p) {
        s += string(p_i, '\0' + initial);
        initial ^= 1;
    }
    return s;
}
int count_swaps(vector<int> b, string const & a) {
    assert (b.size() == a.size());
    if (count(ALL(b), 1) != count(ALL(a), 1)) return INT_MAX;
    int n = a.size();
    int result = 0;
    REP (i, n) if (b[i] != a[i]) {
        REP3 (j, i + 1, n) if (b[i] != b[j]) {
            swap(b[i], b[j]);
            result += j - i;
            break;
        }
    }
    return result;
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    vector<int> b(n); REP (i, n) scanf("%d", &b[i]);
    vector<int> p(n); REP (i, m) scanf("%d", &p[i]);
    int result = min(
        count_swaps(b, deflate_run_length_code(p, 0)),
        count_swaps(b, deflate_run_length_code(p, 1)));
    printf("%d\n", result);
    return 0;
}