Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

int a[20], v[20], p[20], n, m;

int solve(int l) {
	int cnt = 0, pos = 1; 
	for(int i = 1; i <= n; i++) a[i] = v[i];
	for(int k = 1; k <= m; k++) {
		int x = p[k]; 
		while(x) {
			int idx = 0; 
			for(int i = pos; i <= n && !idx; i++) 
				if(a[i] == l) idx = i; 
			if(!idx) return 1e9;
			for(int i = idx; i > pos; i--) 
				swap(a[i], a[i - 1]), ++cnt; 
			++pos; --x;
		} l ^= 1; 
	} 


	return cnt; 
}

int main(int argc, char const *argv[]) {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) 
		scanf("%d", &v[i]); 
	
	for(int i = 1; i <= m; i++) 
		scanf("%d", &p[i]);

	printf("%d\n", min(solve(0), solve(1)));
}
