Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

#define INF (int)(1e9)

signed main(){

  int N, M;
  int ans = 0, ans2 = 0;  vector<int> bit, bit2,  p, e, f;
  
  cin>>N>>M;

  bit.resize(N);
  p.resize(M);

  for(int i = 0; i < N; i++){
    cin>>bit[i];
  }

  bit2 = bit;
  for(int i = 0; i < M; i++){
    cin>>p[i];
    if(i%2){
      for(int j = 0; j < p[i]; j++){
	e.push_back(0);
	f.push_back(1);
      }
    
    } else {
       for(int j = 0; j < p[i]; j++){
	e.push_back(1);
	f.push_back(0);
      }
    }
  }

  for(int i = 0; i < N; i++){
    int x = -1;
    // cout<<"ei  = "<<i<<" "<<e[i]<<" "<<bit[i]<<endl;
    for(int j = i; j < N; j++){
      if(e[i] == bit[j]){
	x = j;
	break;
      }
    }
    
    if(x == -1){
      ans = INF;
      break;
    }
    for(int j = x-1; j >= i; j--){
      bit[j+1] = bit[j];
    }
    ans += x-i;
  }

  
  for(int i = 0; i < N; i++){
    int x = -1;
    //  cout<<"fi  = "<<i<<" "<<f[i]<<" "<<bit2[i]<<endl;
    for(int j = i; j < N; j++){
      if(f[i] == bit2[j]){
	x = j;
	break;
      }
    }
    
    if(x == -1){
      ans2 = INF;
      break;
    }
    for(int j = x-1; j >= i; j--){
      bit2[j+1] = bit2[j];
    }
    ans2 += x-i;
  }

  cout<<min(ans,ans2)<<endl;

  
  return 0;
}

