Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#define PB push_back
using namespace std;
int absint(int a){ return a<0?-a:a; }
int solve(vector<int> a,vector<int> b)
{
  if(a.size()!=b.size()) return 1000;
  int answer=0;
  for(int i=0;i<a.size();++i)
    answer+=absint(a[i]-b[i]);
  return answer;
}
vector<int> bit1(vector<int> a)
{
  vector<int> answer;
  for(int i=0;i<a.size();++i)
    if(a[i]==1) answer.PB(i);
  return answer;
}
int main(void)
{
  vector<int> a,b,c;
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n;++i){
    int tmp;
    cin >> tmp;
    a.PB(tmp);
  }
  for(int i=0;i<m;++i){
    int tmp;
    cin >> tmp;
    for(int j=0;j<tmp;++j){
      b.PB(i%2);
      c.PB((i+1)%2);
    }
  }
  int answer=1000;
  int tmp = solve(bit1(a),bit1(b));
  if(answer>tmp) answer=tmp;
  tmp = solve(bit1(a),bit1(c));
  if(answer>tmp) answer=tmp;
  cout << answer << endl;
  return 0;
}