Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int n, m;
    cin >> n >> m;
    if(n == 0) break;
    vector<bool> bs;
    for(int i = 0; i < n; i++) {
      int c;
      cin >> c;
      bs.push_back(c == 1);
    }
    vector<bool> ts, fs;
    int c = 0;
    bool cur = false;
    for(int i = 0; i < n; i++) {
      if(c == 0) { cin >> c; cur = !cur; }
      ts.push_back(cur);
      fs.push_back(!cur);
      c--;
    }
    auto popcount = [&n](vector<bool> &src) {
      int c = 0;
      for(int i = 0; i < src.size(); i++) {
        if(src[i]) c++;
      }
      return c;
    };
    // now, let's swap!
    auto swaps = [&n,&popcount](vector<bool> &src, vector<bool> &tgt) {
      vector<bool> x(src.size());
      copy(src.begin(), src.end(), x.begin());
      if(popcount(src) != popcount(tgt)) return n * n;
      int cnt = 0;
      for(int i = 0; i < n; i++) {
        if(x[i] != tgt[i]) {
          for(int j = i + 1; j < n; j++) {
            cnt++;
            if(x[j] == tgt[i]) {
              x[j] = x[i];
              x[i] = tgt[i];
              break;
            }
          }
        }
      }
      return cnt;
    };
    cout << min(swaps(bs, ts), swaps(bs,fs)) << endl;
    break;
  }
  return 0;
}


