Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m;
int bits[100];
int len[100];
int seq[100];
bool used[100];
int temp[100];

int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    REP(i, n) {
      scanf("%d", &bits[i]);
    }
    REP(i, m) {
      scanf("%d", &len[i]);
    }
    int ans = 1e+9;
    REP(iter, 2) {
      REP(i, n) {
        temp[i] = bits[i] ^ iter;
      }

      int index = 0;
      REP(i, m) {
        REP(j, len[i]) { seq[index++] = i & 1; }
      }
      int sum = 0;
      REP(i, n) {
        FOR(j, i, n) {
          if (temp[j] != seq[i]) { continue; }
          for (int k = j; k > i; k--) {
            swap(temp[k], temp[k - 1]);
            sum++;
          }
          goto next;
        }
        sum += 1000;
next:;
      }
      ans = min(ans, sum);
    }
    printf("%d\n", ans);
  }
}