Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n, m; cin >> n >> m;
  vector<int> a1(n), a2(n), b(m);
  int cntev1 = 0, cntod1 = 0;
  for(int i=0;i<n;++i) {
    cin >> a1[i];
    a2[i] = a1[i];
    if(a1[i]) {
      cntod1++;
    } else {
      cntev1++;
    }
  }

  int cntev2 = 0, cntod2 = 0;
  bool ev = true;
  for(int i=0;i<m;++i) {
    cin >> b[i];
    if(ev) {
      cntev2 += b[i];
    } else {
      cntod2 += b[i];
    }
    ev = !ev;
  }

  vector<int> s1, s2;
  int nx1 = 0, nx2 = 1;
  if(cntev1 != cntev2 || cntod1 != cntod2) {
    nx1 = -1;
  } else if(cntev1 != cntod2 || cntod1 != cntev2) {
    nx2 = -1;
  }
/*   cout << cntev1 << ":" << cntod1 << endl;
  cout << cntev2 << ":" << cntod2 << endl; */

  for(int i=0;i<m;++i) {
    for(int j=0;j<b[i];++j) {
      if(nx1 != -1) s1.push_back(nx1);
      if(nx2 != -1) s2.push_back(nx2);
    }
    if(nx1 != -1) nx1 = !nx1;
    if(nx2 != -1) nx2 = !nx2;
  }


  // cout << "A" << endl;

  int cnt1 = 0;
  if(nx1 != -1) {
    for(int i=0;i<n;++i) {
      if(a1[i] != s1[i]) {
        int pos = i;
        while(a1[pos] != s1[i]) {
          pos++;
        }
        cnt1 += pos - i;
        int tmppos = a1[pos];
        a1.erase(a1.begin() + pos);
        a1.insert(a1.begin() + i, tmppos);
      }
    }
  } else {
    cnt1 = INF;
  }

  int cnt2 = 0;
  if(nx2 != -1) {
    for(int i=0;i<n;++i) {
      if(a2[i] != s2[i]) {
        int pos = i;
        while(a2[pos] != s2[i]) {
          pos++;
        }
        cnt2 += pos - i;
        int tmppos = a2[pos];
        a2.erase(a2.begin() + pos);
        a2.insert(a2.begin() + i, tmppos);
      }
    }
  } else {
    cnt2 = INF;
  }

  cout << min(cnt1, cnt2) << endl;
}

