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) a.begin(), a.end()
#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;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
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); }

/*--------------------template--------------------*/

int cnt(vi &a, vi &b)
{
	int n = a.size();
	int cnt = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		if (a[i] == b[i]) continue;
		else
		{
			int t;
			for (int j = i - 1; j >= 0; j--)
			{
				if (a[j] == b[i])
				{
					t = j;
					break;
				}
			}
			for (int j = t; j < i; j++)
			{
				swap(a[j], a[j + 1]);
				cnt++;
			}
		}
	}
	return cnt;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vi v(n), w(m);
	REP(i, n) cin >> v[i];
	REP(i, m) cin >> w[i];
	vi a, b;
	int t = 1;
	REP(i, m)
	{
		REP(j, w[i])
		{
			a.push_back(t);
			b.push_back(1 - t);
		}
		t = 1 - t;
	}
	int ans = INF;

	if (count(ALL(v), 1) == count(ALL(a), 1)) chmin(ans, cnt(a, v));
	if (count(ALL(v), 1) == count(ALL(b), 1)) chmin(ans, cnt(b, v));

	cout << ans << endl;
	return 0;
}