Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n, m;

int calc(vector<int> a, vector<int> t){
    int res = 0;
    rep(i, 0, n){
        if(a[i] == t[i]) continue;
        int tmp = INF;
        rep(j, i + 1, n){
            if(a[j] == t[i]){
                tmp = j - i;
                swap(a[i], a[j]);
                break;
            }
        }
        if(tmp == INF) return INF;
        res += tmp;
    }
    return res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    vector<int> b(n), p(m);
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, m) cin >> p[i];
    vector<int> t, s;
    rep(i, 0, m){
        rep(j, 0, p[i]){
            t.push_back(i % 2);
            s.push_back((i + 1) % 2);
        }
    }
    int ans = min(calc(b, t), calc(b, s));
    cout << ans << endl;
}
