Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  int n,m;
  cin >> n >> m;
  vector<int> a;
  vector<int> b;
  vector<int> c;
  REP(i,n){
    int tmp;
    cin >> tmp;
    if(tmp==1) a.push_back(i);
  }
  int len=0;
  REP(i,m){
    int tmp;
    cin >> tmp;
    REP(j,tmp){
      if(i%2) b.push_back(len+j);
      else c.push_back(len+j);
    }
    len+=tmp;
  }
  int answer=1024;
  if(a.size()==b.size()){
    int pena=0;
    REP(i,a.size()) pena+=abs(a[i]-b[i]);
    answer=min(answer,pena);
  }
  if(a.size()==c.size()){
    int pena=0;
    REP(i,a.size()) pena+=abs(a[i]-c[i]);
    answer=min(answer,pena);
  }
  cout << answer << endl;
  return 0;

}