Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;

////////////////////////////////

int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  for(auto&& x:a)cin >> x;
  vector<int> b(m);
  for(auto&& x:b)cin >> x;
  vector<int> c,d;
  c.reserve(n);d.reserve(n);
  for(int i=0;i<b.size();i++){
    for(int j=0;j<b[i];j++){
      if(i&1){
        c.push_back(0);
        d.push_back(1);
      }else{
        c.push_back(1);
        d.push_back(0);
      }
    }
  }
  int lvc = 0, smc = 0, lvd = 0, smd = 0;
  for(int i=0;i<n;i++){
    smc += abs(lvc);
    if(a[i] != c[i]){
      if(c[i])lvc++;
      else lvc--;
    }
    smd += abs(lvd);
    if(a[i] != d[i]){
      if(d[i])lvd++;
      else lvd--;
    }
  }

  if(lvc)smc = 1145141919;
  if(lvd)smd = 1145141919;
  cout << min(smc,smd) << endl;
}


