Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include "bits/stdc++.h"
using namespace std;

#define ll long long

string frm, to;
ll a,b;
char ch;
ll n;

int main()
{
    ll n;
    cin>>a>>b;
    ll ones=0, zeros = 0;
    for(int i=0; i<a; i++) cin>>n, frm+=(n+'0'), ones+=(frm[i]=='1'), zeros+=(frm[i]=='0');
    to = "";
    ll one = 0, zero = 0;
    for(int i=0; i<b; i++)
    {
        cin>>n;
        while(n--)
        {
            if(i%2==0) to+='0', zero++;
            else to+='1', one++;
        }
    }
    string newto="null";

    if(zero!=zeros or one!=ones)
    {
        for(int i=0; i<to.size(); i++) to[i] = (!(to[i]-'0'))+'0';
    }
    else if(zero==one)
    {
        newto = "";
        for(int i=0; i<to.size(); i++) newto += (!(to[i]-'0'))+'0';
    }
    ll res = 0, ans = 0;

//    cout << frm << endl;
//    cout << to << " " << newto << endl;

    string newfrm = frm;

    for(int i=0; i<frm.size(); i++)
    {
        int tmp = i;
        if(frm[i]=='0' && to[i]=='1')
        {
            int cnt = 0;
            while(frm[i]=='0' && i<frm.size()) cnt++, i++;
            swap(frm[i], frm[i-cnt]);
            res += cnt;
        }
        else if(frm[i]=='1' && to[i]=='0')
        {
            int cnt = 0;
            while(frm[i]=='1' && i<frm.size()) cnt++, i++;
            swap(frm[i], frm[i-cnt]);
          //  cout << res << " " << cnt << endl;
            res += cnt;
        }
        i = tmp;
    }

    ans = res;

    if(newto!="null")
    {
        res = 0;
        for(int i=0; i<newfrm.size(); i++)
        {
            int tmp = i;
            if(newfrm[i]=='0' && newto[i]=='1')
            {
                int cnt = 0;
                while(newfrm[i]=='0' && i<newfrm.size()) cnt++, i++;
                swap(newfrm[i], newfrm[i-cnt]);
                res += cnt;
            }
            else if(newfrm[i]=='1' && newto[i]=='0')
            {
                int cnt = 0;
                while(newfrm[i]=='1' && i<frm.size()) cnt++, i++;
                swap(newfrm[i], newfrm[i-cnt]);
              //  cout << res << " " << cnt << endl;
                res += cnt;
            }
            i = tmp;
        }

        ans = min(ans, res);
    }


    cout << ans << endl;


    return 0;
}

