Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int n,m;
    cin >> n >> m;
    vi a(n);
    vi p(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> p[i];
    int ans = INF;
    rep(f,2){
        vi b(n);
        int x = f;
        int k = 0;
        int left = p[k];
        rep(i,n){
            b[i] = x;
            left--;
            if(left == 0){
                k++;
                left = p[k];
                x = 1-x;
            }
        }
        int tmp = 0;
        rep(i,n)if(a[i] != b[i]){
            j=i;
            while(a[i] != b[j] && j < n)j++;
            if(j == n){
                tmp = INF;
                break;
            }
            tmp += j-i;
            b[j] = b[i];
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

