Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;
typedef int weight;
struct edge
{
	int to; weight cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
typedef vector<vector<edge>> Graph;
//int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n, m;
	cin >> n >> m;
	vi to(n), v(m);
	int t = 0;
	REP(i, n)
	{
		cin >> to[i];
		if (to[i]) t++;
	}
	vector<vi> from(2);
	REP(i, m) cin >> v[i];
	REP(i, 2)
	{
		int tmp = i;
		REP(j, m)
		{
			REP(k, v[j])
			{
				from[i].push_back(tmp);
			}
			tmp = 1 - tmp;
		}
	}
	int ans = INF;
	REP(i, 2)
	{
		if (count(ALL(from[i]), 1) != t) continue;
		int cnt = 0;
		vi tmp = from[i];
		REP(j, n)
		{
			if (tmp[j] != to[j])
			{
				for (int k = j;; k++)
				{
					if (tmp[k] == to[j])
					{
						cnt += k - j;
						swap(tmp[j], tmp[k]);
						break;
					}
				}
			}
		}
		chmin(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}