#include <bits/stdc++.h>
using namespace std;
int main() {
	int L;
	cin >> L;
	vector<long long> A(L);
	for (auto& x : A) cin >> x;

	vector<vector<long long>> a(L+1, vector<long long>(5));
	for (int i = 0; i < L; ++ i) {
		auto m = 1LL<<60;
		for (int j = 0; j < 5; ++ j) {
			m = min(m, a[i][j]);
			if (j == 0 || j == 4) {
				a[i+1][j] = m + A[i];
			} else {
				auto k = (A[i] + j + 1) % 2;
				if (A[i] == 0 && j%2 == 1) k = 2;
				a[i+1][j] = m + k;
			}
		}
	}
	/*for (int i = 0; i < L+1; ++ i) {
		for (int j = 0; j < 5; ++ j) {
			cerr << a[i][j] << " ";
		}
		cerr << endl;
	}*/
	auto r = 1LL<<60;
	for (int j = 0; j < 5; ++ j) r = min(r, a[L][j]);
	cout << r << endl;
}
