Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
int score(vector<int> a, vector<int> b) {
    int n = a.size();
    vector<bool> used(n);
    int ans = 0;
    for(int i = 0; i < n; i++) {
        vector<int> c;
        int cnt = 0;
        bool ok = false;
        for(int j = 0; j < n; j++) if(!used[j]) {
            if(b[j] == a[i]) {
                used[j] = true;
                ans += cnt;
                ok = true;
                break;
            }
            cnt ++;
        }
        if(!ok) return INT_MAX;
    }
    return ans;
}

int main(){
    int n, m;
    while(cin >> n >> m) {
        vector<int> a(n);
        REP(i, n) cin >> a[i];
        vector<int> b0, b1;
        REP(i, m) {
            int t;
            cin >> t;
            REP(j, t) {
                b0.push_back((i&1));
                b1.push_back((i&1)^1);
            }
        }
        cout << min(score(a, b0), score(a, b1)) << endl;
    }
    return 0;
}