Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int calc(string s, string target)
{
    int res = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == target[i]) continue;
        bool ok = false;
        for(int j = i + 1; j < s.size(); j++)
        {
            if(target[i] == s[j])
            {
                swap(s[i], s[j]);
                res += j - i;
                ok = true;
                break;
            }
        }
        if(not ok) return INF;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    string b = "", target1 = "", target2 = "";
    for(int i = 0; i < n; i++)
    {
        char ch; cin >> ch;
        b += ch;
    }
    bool flag;
    for(int i = 0; i < m; i++)
    {
        int x; cin >> x;
        if(i == 0) flag = true;
        else if(target1.back() == '1') flag = false;
        else flag = true;
        for(int j = 0; j < x; j++)
        {
            target1 += (flag ? '1' : '0');
            target2 += (flag ? '0' : '1');
        }
    }
    int ans = min(calc(b, target1), calc(b, target2));
    cout << ans << endl;
    return 0;
}


