Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)

int N,M;
int c[2];

int main(){
  cin >> N >> M;
  vector<int>ba(N), p(M);
  rep(i,N) cin >> ba[i];
  rep(i,M) cin >> p[i];
  rep(i,N) c[ba[i]]++;
  int sum=0;
  for(int i=0;i<M;i+=2) sum+=p[i];
  
  int res = 1<<20;
  rep(h,2){
    if(sum!=c[h]) continue;
    int pat = h;
    vector<int>b = ba;
    int cnt = 0;
    int pos = 0;
    rep(i,M){
      for(int j=0;j<p[i];j++){
	if(b[pos] != pat){
	  int k = pos;
	  while(b[k]!=pat) k++;
	  for(int l=k;l>pos;l--){
	    swap(b[l], b[l-1]);
	    cnt++;
	  }
	}
	pos++;
      }
      pat ^= 1;
    }
    res = min(res, cnt);
  }
  cout << res << endl;  
  return 0;
}