Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
#include <limits>

int tsurai(const std::vector<int> &s, const std::vector<int> &t) {
  std::vector<int> u, v;
  for (size_t i=0; i<s.size(); ++i) {
    if (s[i] == 0) u.push_back(i);
    if (t[i] == 0) v.push_back(i);
  }

  if (u.size() != v.size()) {
    return std::numeric_limits<int>::max();
  }

  int res=0;
  for (size_t i=0; i<u.size(); ++i) {
    //fprintf(stderr, "%d, %d\n", u[i], v[i]);
    res += std::abs(u[i]-v[i]);
  }

  return res;
}

int main() {
  int N, M;
  scanf("%d %d", &N, &M);

  std::vector<int> b(N), c(N), p(M);
  for (int i=0; i<N; ++i) {
    scanf("%d", &b[i]);
    c[i] = b[i] ^ 1;
  }

  for (int i=0; i<M; ++i)
    scanf("%d", &p[i]);

  std::vector<int> pb, pc;
  for (int i=0; i<M; ++i) {
    for (int j=0; j<p[i]; ++j) {
      pb.push_back(i&1);
      pc.push_back(pb.back()^1);
    }
  }

  int res=std::numeric_limits<int>::max();
  for (const auto &bc: {b, c})
    for (const auto &pbc: {pb, pc})
      res = std::min(res, tsurai(bc, pbc));

  printf("%d\n", res);
  return 0;
}