Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <bits/stdc++.h>
using namespace std;

int needswap(vector<int> s, vector<int> g){
  int res = 0;
  for(int i = 0; i < s.size() ; i++){
    if(s[i] != g[i]){
      int r = -1;
      for(int k = i; k < s.size(); k++){
        if(s[k] == g[i]){
          r = k;
          break;
        } 
      }
      if(r == -1) return 1e8;
      swap(s[i], s[r]);
      res += r - i;
    }
  }
  return res;
}
int main(){
  int n, m; cin >> n >> m;
  vector<int> b(n), p(m);
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  for(int i = 0; i < m; i++){
    cin >> p[i];
  }
  vector<vector<int> > g(2, vector<int>());
  for(int i = 0; i <= 1; i++){
    int ff = i;
    for(int c : p){
      for(int k = 0; k < c; k++) g[i].push_back(ff);
      ff = !ff;
    }
  }
  cout << min(needswap(b, g[0]), needswap(b, g[1])) << endl;
}

/*

0 1 0 1 1

0 0 1 1 1
1 1 1 0 0


0 0 1 1 1 0 0

1 1 0 0 0 0 1 
 1 2 1 0

0 0 0 1 0 1 1 0

1 1 1 0 0 0 0 0
 1 2 3 2 2 1 0
*/ 