Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

vi trans(vi p, int k){
  vi a;
  for(int i=0;i<p.size();i++){
    for(int j=0;j<p[i];j++){
      a.push_back(k);
    }
    k = 1-k;
  }
  return a;
}

vi pos(vi a){
  vi res;
  for(int i=0;i<a.size();i++){
    if(a[i])res.push_back(i);
  }
  return res;
}

int main(){
  int n,m;
  cin >> n >> m;
  vi b(n),p(m);
  for(int i=0;i<n;i++)cin >> b[i];
  for(int j=0;j<m;j++)cin >> p[j];
  
  int ans = 1e9;
  for(int c=0;c<2;c++){
    vi a = trans(p,c);
    vi pos1 = pos(b), pos2 = pos(a);
    if(pos1.size() != pos2.size())continue;

    int sum = 0;
    for(int i=0;i<pos1.size();i++){
      sum += abs(pos1[i] - pos2[i]);
    }
    ans = min(ans,sum);
  }
  cout << ans << endl;
}