Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int calc(vector<int>& v, vector<int>& w) {
	if (v.size() != w.size()) return INT_MAX;
	int res = 0;
	for (int i = 0; i < v.size(); i++)
		res += abs(v[i] - w[i]);
	return res;
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> v;
	for (int i = 0; i < N; i++) {
		int b; cin >> b;
		if (b) v.push_back(i);
	}
	vector<int> w1, w2;
	int i = 0; bool flag = false;
	while (M--) {
		int p; cin >> p;
		while (p--) {
			if (flag) w1.push_back(i);
			else w2.push_back(i);
			i++;
		}
		flag = !flag;
	}
	cout << min(calc(v, w1), calc(v, w2)) << endl;;
} 