Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <vector>
#include <string>
using namespace std;
char bit[] = {'0','1'};
string str = "";
int inf = 1<<28;
int pos_dif(string s,int index,char op){
  if(index ==  str.size())return -1;
  if(s[index] != str[index] && str[index] == op)return index;
  
  return pos_dif(s,index+1,op);
}
int swap_bit(int index,string s,int cnt){
  if(s.size() == 1) return 0;
  if(index == str.size()){
	return cnt;
  }

  if(str[index] == s[index]) {
	return swap_bit(index+1,s,cnt);
  }
  int pos = pos_dif(s,index+1,s[index]);
  if(pos == -1)return inf;
  char tmp = s[index];
  s[index] = s[pos];
  s[pos] = tmp;
  return swap_bit(index+1,s,cnt+pos-index);
}
int main(){
  
  int n,m;
  cin >> n >> m;

  for(int i = 0;i < n;i++){
	string tmp;
	cin >> tmp;
	str += tmp;
  }
  string s1 = "",s2 = "";
  for(int i = 0;i < m;i++){
	int tmp;
	cin >> tmp;
	for(int j = i;j < i+tmp;j++){
	  s1 += bit[i%2];
	  s2 += bit[(i+1)%2];
	}
  }
  cout << min(swap_bit(0,s1,0),swap_bit(0,s2,0)) << endl;

  return 0;
}