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<(int)(n);i++)

using namespace std;

const int INF = 1e+8;

int main() {
  int n,m;
  cin>>n>>m;
  bitset<15> bs;
  REP(i,n) {
    int j;
    cin>>j;
    bs[n-i-1]=j;
  }
  int num = bs.to_ulong();
  vector<int> dist(1<<n,INF);
  dist[num] = 0;
  queue<int> q;
  q.push(num);
  while(!q.empty()) {
    int i=q.front();q.pop();
    bitset<15> b(i);
    REP(j,n-1) {
      auto cp = b;
      bool tmp = cp[j];
      cp[j] = cp[j+1];
      cp[j+1] = tmp;
      int nb = cp.to_ulong();
      if (dist[nb] > dist[i] + 1) {
        dist[nb] = dist[i] + 1;
        q.push(nb);
      }
    }
  }
  int g1,g2;
  REP(i,m) {
    int k;
    cin>>k;
    REP(j,k) {
      g1 *= 2;
      g1 |= i & 1;
      g2 *= 2;
      g2 |= 1 - (i & 1);
    }
  }
  cout << min(dist[g1], dist[g2]) << endl;
  return 0;
}