Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  int n, m;
  cin >> n >> m;
  int start = 0;
  REP(i, n){
    int k;
    cin >> k;
    start = (start << 1) | k;
  }
  int goal1 = 0, goal2 = 0;
  int t = 0;
  REP(i, m){
    int k;
    cin >> k;
    REP(j, k){
      goal1 = (goal1 << 1) | t;
      goal2 = (goal2 << 1) | (~t & 1);
    }
    t = ~t & 1;
  }

  vb G(1 << (n + 1));
  G[start] = true;
  queue<int> que;
  que.push(start);
  que.push(-1);
  int step = 0;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    if(p == goal1 || p == goal2) {
      cout << step << endl;
      break;
    }

    if(p == -1) {
      step++;
      que.push(p);
      continue;
    }

    REP(i, n - 1){
      int trade = 3 << i;
      int disable = p & trade;
      int next = p ^ trade;
      if (disable == 0 || disable == trade) continue;
      if(next >= (1 << n)) continue;
      if(G[next]) continue;
      G[next] = true;
      que.push(next);
    }
  }
}