Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;

const int INF = 1<<28;
int N, M;
vector<int> B, P;

int numOfSwaps(const vector<int> &a) {
  int n = a.size();
  int res = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i+1; j < n; ++j) {
      res += (a[i] > a[j]);
    }
  }
  return res;
}

int calc(const vector<int> &a) {
  if(accumulate(a.begin(), a.end(), 0) !=
     accumulate(B.begin(), B.end(), 0)) return INF;
  vector<int> b(N, -1);
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      if(b[j] == -1 && B[j] == a[i]) {
        b[j] = i;
        break;
      }
    }
  }
  return numOfSwaps(b);
}

int main() {
  cin >> N >> M;
  B.resize(N); P.resize(M);
  for(int i = 0; i < N; ++i) cin >> B[i];
  for(int i = 0; i < M; ++i) cin >> P[i];
  vector<int> C(N), D(N);
  for(int i = 0, j = 0; j < M; ++j) {
    for(int k = 0; k < P[j]; ++k, ++i) C[i] = j & 1;
  }
  for(int i = 0; i < N; ++i) D[i] = 1 - C[i];
  cout << min(calc(C), calc(D)) << endl;
  return 0;
}