Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;
int INF = 100000;
int count(vector<int> &a){
  int N = a.size();
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (a[i] == 1){
      ans++;
    }
  }
  return ans;
}
int solve(vector<int> a, vector<int> b){
  int N = a.size();
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (a[i] != b[i]){
      int p = i;
      while (a[i] != b[p]){
        p++;
      }
      for (int j = p - 1; j >= i; j--){
        swap(b[j], b[j + 1]);
        ans++;
      }
    }
  }
  return ans;
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b[i];
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++){
    cin >> p[i];
  }
  vector<int> c;
  for (int i = 0; i < M; i++){
    for (int j = 0; j < p[i]; j++){
      c.push_back(i % 2);
    }
  }
  int ans = INF;
  if (count(b) == count(c)){
    ans = min(ans, solve(b, c));
  }
  for (int i = 0; i < N; i++){
    c[i] = 1 - c[i];
  }
  if (count(b) == count(c)){
    ans = min(ans, solve(b, c));
  }
  cout << ans << endl;
}
