Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>

using namespace std;

int main(void){
    int n, m;
    cin >> n >> m;
    string a,b,c;
    int cnta = 0, cntb = 0, cntc = 0;
    for (int i = 0; i < n; i++) {
        char d; cin >> d;
        if (d == '1') cnta++;
        a += d;
    }
    for (int i = 0; i< m; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            if (i%2) {
                b += '1'; cntb++;
                c += '0';
            }
            else {
                b += '0';
                c += '1'; cntc++;
            }
        }
    }
    
    int ans = 1e9;
    if (cnta == cntb) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] != b[i]) {
                int j = i;
                while (b[j] != a[i]) j++;
                sum += j-i;
                swap(b[i], b[j]);
            }
        }
        ans = min(ans, sum);
    }
    
    if (cnta == cntc) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] != c[i]) {
                int j = i;
                while (c[j] != a[i]) j++;
                sum += j-i;
                swap(c[i], c[j]);
            }
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}