Example

Input

6 3
1 0 0 1 0 1
1 3 2


Output

1
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	vector<int> s;
	int N, M;
	cin >> N >> M;
	for(int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		s.push_back(tmp + '0');
	}
	vector<int> p[2];
	int fill = 0;
	for(int i = 0; i < M; i++) {
		int tmp;
		cin >> tmp;
		for(int j = 0; j < tmp; j++) {
			p[0].push_back(!!fill+'0');
			p[1].push_back(!fill+'0');
		}
		fill = !fill;
	}

	int ans = 10000;
	for(int i = 0; i < 2; i++) {
		int tmp = 0;
		for(int j = 0; j < s.size(); j++) {
			if(s[j] != p[i][j]) {
				int sw = -1;
				for(int k = 1; k + j < s.size(); k++) {
					if(s[j] == p[i][j+k]) {
						sw = k;
						break;
					}
				}
				if(sw<0) {
				//	cout << i << "," << j << endl;
					tmp = 10000;
				}

				else {
					for(int k = j+sw-1; k >= j; k--)
						swap(p[i][k], p[i][k+1]);
					tmp += sw;
				}
			}
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}