#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int n;
ll a[1 << 18];

ll s[1 << 18];
ll r[1 << 18];

struct SegT {
private:
	int n; vector<ll> node, lazy;
	const ll init_c = INF;
public:
	SegT(int sz) {
		n = 1;
		while (n < sz)n <<= 1;
		node.resize(2 * n - 1, init_c);
		lazy.resize(2 * n - 1, 0);
	}
	ll f(ll a, ll b) {
		return min(a, b);
	}
	void eval(int k, int l, int r) {
		node[k] += lazy[k];
		if (r - l > 1) {
			lazy[2 * k + 1] += lazy[k];
			lazy[2 * k + 2] += lazy[k];
		}
		lazy[k] = 0;
	}
	void add(ll x, int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l && r <= b) {
			lazy[k] += x; eval(k, l, r);
		}
		else {
			add(x, a, b, k * 2 + 1, l, (l + r) / 2);
			add(x, a, b, k * 2 + 2, (l + r) / 2, r);
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return init_c;
		if (a <= l && r <= b)return node[k];
		else {
			ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
	void update(int k, ll x) {
		k += n - 1;
		node[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[2 * k + 1], node[2 * k + 2]);
		}
	}
};
ll u[1 << 18];
ll cc[1 << 18];

ll invs[1 << 18];
ll sums[1 << 18];
ll invu[1 << 18];
int main() {
	cin >> n;
	SegT rs(n + 1);
	SegT zs(n + 1);
	SegT ls(n + 1);
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sums[i + 1] = sums[i] + a[i];
		if (a[i] % 2==0)sum++;
	}
	per(i, n) {
		int t;
		if (a[i] % 2)t = 1;
		else if (a[i] == 0)t = 2;
		else t = 0;
		invs[i] = invs[i + 1] + t;
	}
	ll ccsum = 0;
	rep(i, n) {
		ccsum += a[i];
		ls.update(i + 1, invs[i + 1]+ccsum);
	}
	ls.update(0, invs[0]);
	rep(i, n + 1) {
		invu[i] = ls.query(0, i+1)-invs[i];
	}
	rep(i, n) {
		int t;
		if (a[i] % 2)t = 1;
		else if (a[i] == 0)t = 2;
		else t = 0;
		s[i + 1] = s[i] + t;
	}
	/*rep(i, n + 1) {
		cout << i<<" "<<s[i] <<endl;
	}
*/
	ll csum = 0;
	per(i, n) {
		csum += a[i];
		rs.update(i, s[i]+csum);
		//cout << i << " " << s[i] + csum << endl;
	}
	rs.update(n, s[n]);
	rep(i, n + 1) {
		u[i] = rs.query(i, n + 1) - s[i];
		//cout << i << " " << u[i] << endl;
	}
	ll cnt = 0;
	zs.update(0, u[0]);
	rep(i, n) {
		if (a[i] % 2==0)cnt++;
		cc[i + 1] = cnt; u[i+1] += cnt;
		zs.update(i + 1, u[i + 1]);
	}
	ll ans = INF;
	//左端を探索
	rep(i, n + 1) {
		ll z = invu[i] + zs.query(i, n + 1) - cc[i];
		ans = min(ans, z);
		//cout << z << endl;
	}
	//cout << endl;
	cout << ans << endl;
	//cout << endl;
	/*rep(i, n + 1) {
		cout << invu[i] << endl;
	}*/
	//stop
	return 0;
}

Measured memory_bytes: 38656