#define y1 askjdkasldjlkasd
#include <bits/stdc++.h>
#undef y1

using namespace std;

#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)
#define clr(x) memset(x, 0, sizeof(x))
#define cpy(x,y) memcpy(x, y, sizeof(y))
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

#ifdef _DEBUG
#define LOCAL
#endif

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while (0)
#endif

double START_TIME;

void exit() {
#ifdef LOCAL	
	cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl;
#endif	
	exit(0);
}

template<typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
	fi(0, sz(v) - 1) {
		os << v[i] << " ";
	}
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T> t) {
	for (auto z : t) {
		os << z << " ";
	}
	return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
	cerr << endl;
	for (auto z : t) {
		os << "\t" << z.first << " -> " << z.second << endl;
	}
	return os;
}

#ifdef LOCAL
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#define dbg1(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 1; ABC <= n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) while(0){}
#define dbg0(x, n) while(0){}
#define dbg1(x, n) while(0){}
#endif

#ifdef LOCAL
#define ass(x) if (!(x)) { cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); }
#else
#define ass(x) assert(x)
#endif

///////////////////////////////////////////////////

const int MAX = 2e5 + 41;
const ll INF = 1e18;

int n;
int a[MAX];
ll pref[MAX];
ll suf[MAX];
ll d[MAX][5];

int geteven(int x) {
	if (x == 0) return 2;
	return x % 2;
}

int getodd(int x) {
	return 1 - (x % 2);
}

void solve() {
	fi(1, n) {
		pref[i] = pref[i - 1] + a[i];
	}
	fdi(n, 1) {
		suf[i] = suf[i + 1] + a[i];
	}
	ll ans = accumulate(a + 1, a + n + 1, 0LL);
	
	fill_n(&d[0][0], MAX * 5, INF);
	d[1][0] = 0;
	fi(1, n) {
		fj(0, 4) {
			if (d[i][j] < 0) continue;
			if (j == 0) {
			  d[i + 1][0] = min(d[i + 1][0], d[i][0] + a[i]);
			  d[i + 1][1] = min(d[i + 1][1], d[i][0] + geteven(a[i]));
				d[i + 1][2] = min(d[i + 1][2], d[i][0] + getodd(a[i]));
				d[i + 1][3] = min(d[i + 1][3], d[i][0] + geteven(a[i]));
				d[i + 1][4] = min(d[i + 1][4], d[i][0] + a[i]);
			} else if (j == 1) {
				d[i + 1][1] = min(d[i + 1][1], d[i][1] + geteven(a[i]));
				d[i + 1][2] = min(d[i + 1][2], d[i][1] + getodd(a[i]));
				d[i + 1][3] = min(d[i + 1][3], d[i][1] + geteven(a[i]));
				d[i + 1][4] = min(d[i + 1][4], d[i][1] + a[i]);
			} else if (j == 2) {				
				d[i + 1][2] = min(d[i + 1][2], d[i][2] + getodd(a[i]));
				d[i + 1][3] = min(d[i + 1][3], d[i][2] + geteven(a[i]));
				d[i + 1][4] = min(d[i + 1][4], d[i][2] + a[i]);
			} else if (j == 3) {
				d[i + 1][3] = min(d[i + 1][3], d[i][3] + geteven(a[i]));
				d[i + 1][4] = min(d[i + 1][4], d[i][3] + a[i]);
			} else if (j == 4) {				
				d[i + 1][4] = min(d[i + 1][4], d[i][4] + a[i]);
			}
		}
	}

	fi(0, 4) {
		ans = min(ans, d[n + 1][i]);
	}

	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	START_TIME = (double)clock();
#endif
	
	scanf("%d", &n);
	fi(1, n) {
		scanf("%d", &a[i]);
	}
	solve();

	exit();
	return 0;
}





Measured memory_bytes: 12032