Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int n, m;
	cin >> n >> m;
	VI b(n), p(m);
	REP(i,n) cin >> b[i];
	REP(i,m) cin >> p[i];
	int ones = 0;
	REP(i,n) ones += b[i];
	VI t(n);
	int x = p[0];
	FOR(i,1,m-1){
		FOR(j,x,x+p[i]-1){
			t[j] = t[x-1] ^ 1;
		}
		x += p[i];
	}

	int ans = 1e9;
	int s1 = 0, res1 = 0;
	int s2 = 0, res2 = 0;
	REP(i,n){
		s1 += b[i] - t[i];
		res1 += abs(s1);
		s2 += b[i] - (t[i] ^ 1);
		res2 += abs(s2);
	}
	if (s1 == 0) ans = min(ans, res1);
	if (s2 == 0) ans = min(ans, res2);

	cout << ans << endl;

    return 0;
}