Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> bit[2];
  for(int i = 0; i < N; i++){
    int b; cin >> b;
    bit[0].push_back(b);
    bit[1].push_back(b);
  }
  vector<int> run[2];
  for(int i = 0; i < M; i++){
    int p; cin >> p;
    for(int j = 0; j < p; j++)
      run[0].push_back(i%2), run[1].push_back(!(i%2));    
  }
  int ans = 100;
  for(int i = 0; i < 2; i++){
    int cnt = 0;
    for(int j = 0; j < N; j++){
      if(bit[i][j] == run[i][j]) continue;
      int pos = j;
      while(pos < N && bit[i][j] == bit[i][pos]) pos++;
      if(pos == N){ cnt = 100; break; }
      for(int k = pos; k > j; k--) swap(bit[i][k], bit[i][k-1]), cnt++;      
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}