Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<iostream>
#include<algorithm>
using namespace std;

int n, m;
bool search(int* bit, int p, int x, int &ans){
  for (int i = p; i < n; i++) {
    if(bit[i] == x){
      ans += i - p;
      bit[i] = (x+1)&1;
      bit[p] = x&1;
      return true;
    }
  }
  return false;
}

int main(int argc, char *argv[]){
  cin >> n >> m;
  int bit[n], len[m], bcopy[n];
  for (int i = 0; i < n; i++) {
    cin >> bit[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> len[i];
  }
  //1 0??????
  int x, ans[2] = {0}, tmp;
  for (int k = 0; k < 2; k++) {
    tmp = 0;
    x = k;
    for (int i = 0; i < n; i++) {
      bcopy[i] = bit[i];
    }
    for (int i = 0; i < m; i++) {
      x = (x+1)&1;
      for (int j = 0; j < len[i]; j++) {
        if(bcopy[j + tmp] != x){
          if(!search(bcopy, j + tmp, x, ans[k]))
            ans[k] = 1e9;
        }
      }
      tmp += len[i];
    }
  }
  std::cout << min(ans[0], ans[1]) << std::endl;
  return 0;
}