Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

void g(vector<int>&clu)
{
	int zer[2] = {};
	for (int i = 0; i < clu.size(); ++i)
	{
		if (clu[i] == 0)zer[0]++; else zer[1]++;
		clu[i] = clu[i] * 114514 + zer[clu[i]];
	}
}

int f(vector<int>war, vector<int>to, int n)
{
	g(war); g(to);
	int cost = 0;
	for (int i = 0; i < n; ++i)
	{
		int val = war[i];
		int pl = find(to.begin(), to.end(), val) - to.begin();
		if (pl == n)
		{
			return 114514810;
		}
		cost += abs(pl - i);
	}
	return cost / 2;
}

int main(void)
{
	int n, m;
	cin >> n >> m;
	vector<int>war, one, two;
	for (int i = 0; i < n; ++i)
	{
		int tmp; cin >> tmp;
		war.push_back(tmp);
	}
	bool flag = false;
	for (int i = 0; i < m; ++i)
	{
		int tmp; cin >> tmp;
		for (int j = 0; j < tmp; ++j)
		{
			one.push_back(flag);
			two.push_back(!flag);
		}
		flag = !flag;
	}
	cout << min(f(war, one, n), f(war, two, n)) << endl;
	return 0;
}