Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n, m;
	cin >> n >> m;

	vector<int> a(n), b(m);
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];


	vector<int> c, d;
	rep(i, m) {
		rep(j, b[i]) {
			if(i & 1) {
				c.push_back(1);
				d.push_back(0);
			} else {
				c.push_back(0);
				d.push_back(1);
			}
		}
	}

	int ans = INF, res = 0;
	vector<int> t(a.begin(), a.end());
	rep(i, n) {
		if(t[i] == c[i]) continue;

		REP(j, i+1, n) {
			if(c[i] == t[j]) {
				for(int k = j; k-1 >= i; k--) {
					swap(t[k], t[k-1]);
					res++;
				}
				break;
			}
		}
	}

	bool flag = true;
	rep(i, n) {
		if(t[i] == c[i]) continue;
		flag = false;
	}

	if(flag) {
		ans = min(ans, res);
	}

	res = 0;
	rep(i, n) t[i] = a[i];

	rep(i, n) {
		if(t[i] == d[i]) continue;

		REP(j, i+1, n) {
			if(d[i] == t[j]) {
				for(int k = j; k-1 >= i; k--) {
					swap(t[k], t[k-1]);
					res++;
				}
				break;
			}

		}
	}

	flag = true;
	rep(i, n) {
		if(t[i] == d[i]) continue;
		flag = false;
	}

	if(flag) {
		ans = min(ans, res);
	}

	cout << ans << endl;

	return 0;
}