Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;

int n, m;
string b = "";
int p[15];

int solve(int  sn)
{
    string nowp = "";
    int ans = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < p[i]; j++){
            if(i % 2 == 0) nowp += sn + '0';
            else nowp += (sn + 1) % 2 + '0';
        }
    }
    // cout << nowp << endl;
    for(int i = 0; i < nowp.length() - 1; i++){
        if(nowp[i] != b[i]){
            int cnt = 1;
            while(nowp[i + cnt] != b[i] && i + cnt < nowp.length()) cnt++;
            // cout << cnt << endl;
            for(int j = i + cnt; j > i; j--){
                swap(nowp[j], nowp[j - 1]);
                ans++;
            }
        }
    }
    // cout << ans << endl;
    return ans;
}


int main()
{
    cin >> n >> m;
    int bzeronum = 0,pevennum = 0;
    char c;
    for(int i = 0; i < n; i++){
        cin >> c;
        if(c == '0') bzeronum++;
        b += c;
    }
    for(int i = 0; i < m; i++){
        cin >> p[i];
        if(i % 2 == 0) pevennum += p[i];
    }
    int ans = 1000;
    if(bzeronum == pevennum) ans = min(ans, solve(0));
    if(n - bzeronum == pevennum) ans = min(ans, solve(1));
    cout << ans << endl;
}