Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int calc(vi a,vi b)
{
	if(count(all(a),1)!=count(all(b),1))
		return INF;
	int n=a.size(),cnt=0;
	for(int i=0,j;i<n;i++){
		if(a[i]==b[i]) continue;
		for(j=i;j<n && b[j]!=a[i];j++);
		for(;j>i;j--,cnt++) swap(b[j],b[j-1]);
	}
	return cnt;
}

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		vi a(n),b;
		rep(i,n) cin>>a[i];
		rep(i,m){
			int t; cin>>t;
			int x=b.empty()?0:!b.back();
			rep(j,t) b.push_back(x);
		}
		
		int res=calc(a,b);
		rep(i,n) b[i]^=1;
		res=min(res,calc(a,b));
		cout<<res<<endl;
	}
}