Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int IINF = INT_MAX;

int n, m;
int solve(vector<int> b, vector<int> a){
    int res = 0;
    for(int i=0;i<n;i++){
        if(b[i] != a[i]){
            int j = i+1;
            while(j<n && b[j]!=a[i]) j++;
            if(j==n) return IINF;
            swap(b[i],b[j]);
            res += j-i;
        }
    }
    return res;
}

int main() {
    cin >> n >> m;
    vector<int> b(n), a(n);
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0,j=0;i<m;i++){
        int p;
        cin >> p;
        for(int k=0;k<p;k++){
            a[j++] = i%2;
        }
    }
    int ans;
    ans = solve(b, a);
    for(int i=0;i<n;i++) a[i] ^= 1;
    ans = min(ans, solve(b,a));
    cout << ans << endl;
    return 0;
}

