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 solve(vector<int> a,vector<int> b){
  if(a.size()!=b.size()) return 1048576;
  SORT(a);
  SORT(b);
  int answer=0;
  REP(i,a.size()) answer+=abs(a[i]-b[i]);
  return answer;
}
int main(void)
{
  int n,m;
  cin >> n >> m;
  vector<int> bi(n),ru(m);
  REP(i,n) cin >> bi[i];
  REP(i,m) cin >> ru[i];
  vector<int> bii,ru0i,ru1i;
  REP(i,n) if(bi[i]) bii.push_back(i);
  int tmp=0;
  bool flag=true;
  REP(i,m-1) ru[i+1]+=ru[i];
  REP(i,m){
    for(flag=!flag;tmp<ru[i];++tmp)
      if(flag) ru0i.push_back(tmp);
      else ru1i.push_back(tmp);
  }
  cout << min(solve(bii,ru0i),solve(bii,ru1i)) << endl;
  return 0;
}