Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
const int INF = 114514810;
using namespace std;
typedef long long LL;

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> B(n);
  rep(i,n) cin>>B[i];
  vector<int> p(m);
  rep(i,m) cin>>p[i];
  vector<int> tg(n);

  int k=0;
  vector<int> b = B;
  rep(i, p.size())rep(j, p[i]) tg[k++]=i%2;
  int ans = INF;
  int tmp = 0;
  rep(i, n){
    if(tmp == INF) break;
    if(b[i] == tg[i]) continue;
    rep(j, n){
      if(i+j >= n){
        tmp = INF;
        break;
      }
      if(b[i+j] == tg[i]){
        swap(b[i], b[i+j]);
        tmp += j;
        break;
      }
    }
  }
  ans = min(ans, tmp);
  k=0;
  rep(i, p.size())rep(j, p[i]) tg[k++]=(i+1)%2;
  tmp = 0;
  b = B;
  rep(i, n){
    if(tmp == INF) break;
    if(b[i] == tg[i]) continue;
    rep(j, n){
      if(i+j >= n){
        tmp = INF;
        break;
      }
      if(b[i+j] == tg[i]){
        swap(b[i], b[i+j]);
        tmp += j;
        break;
      }
    }
  }
  ans = min(ans, tmp);
  cout << ans << endl;
}


