Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
using namespace std;

int n, m;

int f(string s, const string t) {
	int ret = 0;
	for (int i = 0; i < n; i++) {
		int j = i;
		while (t[i] != s[j]) j++;
		ret += abs(i - j);
		swap(s[i], s[j]);
	}
	return ret;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (cin >> n >> m) {
		string s;
		vector<int> p(m);
		for (int i = 0; i < n; i++) {
			char c;
			cin >> c;
			s += c;
		}
		for (int i = 0; i < m; i++) {
			cin >> p[i];
		}

		int ans = 1e9;
		for (int i = 0; i <= 1; i++) {
			string t;
			int x = i;
			for (int j = 0; j < m; j++) {
				string a = string(p[j], char('0' + x));
				t += a;
				x = !x;
			}
			assert(t.size() == n);
			if (count(s.begin(), s.end(), '0') != count(t.begin(), t.end(), '0')) continue;
			if (count(s.begin(), s.end(), '1') != count(t.begin(), t.end(), '1')) continue;
			ans = min(ans, f(s, t));
		}
		cout << ans << endl;
	}
}