Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {

  long long int n, m;
  cin >> n >> m;

  vector< long long int > b;

  long long int cnt_0 = 0;
  long long int cnt_1 = 0;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in;
    cin >> in;
    b.push_back( in );

    if ( in == 0 ) cnt_0++;
    if ( in == 1 ) cnt_1++;

  }

  vector< long long int > v0, v1;
  long long int cnt_a = 0;
  long long int cnt_b = 0;

  for ( long long int i = 0; i < m; i++ ) {

    long long int in;
    cin >> in;

    if ( ( i % 2 ) == 0 ) {
      cnt_a += in;
      for ( long long int j = 0; j < in; j++ ) {
	v0.push_back(0);
	v1.push_back(1);
      }
    }else {
      cnt_b += in;
      for ( long long int j = 0; j < in; j++ ) {
	v0.push_back(1);
	v1.push_back(0);
      }
    }

  }

  long long int ans = 100000000;

  if ( cnt_0 == cnt_a ) {

    long long int c = 0;
    long long int k = 0;

    for ( long long int i = 0; i < n; i++ ) {

      if ( v0[i] == 1 ) continue;
      while(1) {
	if ( b[k] == 0 ) {
	  c += abs( k - i );
	  break;
	}
	k++;
      }
      k++;

    }

    ans = min( ans, c );

  }

  if ( cnt_0 == cnt_b ) {

    long long int c = 0;
    long long int k = 0;

    for ( long long int i = 0; i < n; i++ ) {

      if ( v1[i] == 1 ) continue;
      while(1) {
	if ( b[k] == 0 ) {
	  c += abs( k - i );
	  break;
	}
	k++;
      }
      k++;

    }

    ans = min( ans, c );

  }

  cout << ans << endl;

  return 0;

}