Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> B(n), P(m), one;
  for(int i = 0; i < n; ++i){
    cin >> B[i];
    if(B[i]) one.push_back(i);
  }

  for(int i = 0; i < m; ++i) cin >> P[i];
  int ans = 1000000000;
  for(int i = 0; i < 2; ++i){
    vector<int> A(n);
    int t = 0;
    vector<int> one_;
    for(int j = 0; j < m; ++j){
      for(int k = 0; k < P[j]; ++k){
        A[t] = (i+j)%2;
        if((i+j)%2) one_.push_back(t);
        ++t;
      }
    }
    if(one.size() != one_.size()) continue;
    int d = 0;
    for(int j = 0; j < one.size(); ++j)
      d += abs(one[j]-one_[j]);
    ans = min(d,ans);
  }
  cout << ans << endl;
  return 0;
}

