Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>

using namespace std;

#define REP(i,n) for (int i=0; i<n; i++)

int n, m, b[20], bitstr[20], p[20];

int count(int flg){
	int ret=0, c=0, count;
	REP(i,n){
		bitstr[i] = b[i];
	}
	count = p[c];
	REP(i,n){
		if (bitstr[i]!=flg){
			bool notfound=1;
			for (int k=i+1; k<n; k++){
				if (bitstr[k]==flg){
					ret += k-i;
					notfound = false;
					bitstr[i] = flg;
					bitstr[k] = (flg ^ 1);
					break;
				}
			}
			if (notfound){
				ret = -1;
				break;
			}
		}
		count--;
		if (count==0){
			flg = (flg ^ 1);
			c++;
			count = p[c];
		}
	}
	return ret;
}

int main(){
	int count0=0, count1=0;
	
	cin >> n >> m;
	REP(i,n){
		cin >> b[i];
	}
	REP(i,m){
		cin >> p[i];
	}
	
	// cout << (flg ^ 1) << endl;
	count0 = count(0);
	count1 = count(1);
	
	// printf("count0: %d, count1: %d\n", count0, count1);
	
	if (count0<0){
		cout << count1 << endl;
	}else if (count1<0){
		cout << count0 << endl;
	}else{
		cout << min(count0, count1) << endl;
	}
	
}
