/************
< 주소 >      :
*************
< 해결방안 >   :


*************
< 오답노트 >   :

*************/

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL_BOOKNU
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// ........................macro.......................... //
#define FOR(i, f, n) for(int (i) = (f); (i) < (int)(n); ++(i))
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (int)(n); --(i))
#define pb push_back
#define emb emplace_back
#define fi first
#define se second
#define ENDL '\n'
#define sz(A) (int)(A).size()
#define ALL(A) A.begin(), A.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define next next9876
#define prev prev1234
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef long long i64;
typedef unsigned long long ui64;
// inline i64 GCD(i64 a, i64 b) { if(b == 0) return a; return GCD(b, a % b); }
inline int getidx(const vi& ar, int x) { return lower_bound(ALL(ar), x) - ar.begin(); } // 좌표 압축에 사용: 정렬된 ar에서 x의 idx를 찾음
inline i64 GCD(i64 a, i64 b) { i64 n; if(a < b) swap(a, b); while(b != 0) { n = a % b; a = b; b = n; } return a; }
inline i64 LCM(i64 a, i64 b) { if(a == 0 || b == 0) return GCD(a, b); return a / GCD(a, b) * b; }
inline i64 CEIL(i64 n, i64 d) { return n / d + (i64)(n % d != 0); } // 음수일 때 이상하게 작동할 수 있음.
inline i64 ROUND(i64 n, i64 d) { return n / d + (i64)((n % d) * 2 >= d); }
inline i64 POW(i64 a, i64 n) {
	assert(0 <= n);
	i64 ret;
	for(ret = 1; n; a = a*a, n /= 2) { if(n%2) ret *= a; }
	return ret;
}
template <class T> ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	int cnt = 0;
	for(auto vv : v) { os << vv; if(++cnt < v.size()) os << ","; }
	return os << "]";
}
template <class T> ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	int cnt = 0;
	for(auto vv : v) { os << vv; if(++cnt < v.size()) os << ","; }
	return os << "]";
}
template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> p) { return os << "(" << p.fi << "," << p.se << ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H, debug_out(T...); }
// ....................................................... //

const int MAXN = 2e5+10;
const i64 INF = 0x7fffffffffffffff;
i64 n, ar[MAXN], ps[MAXN];
i64 t1[MAXN], t2[MAXN], dp[MAXN]; // [..i] (i..]
void input() {
	cin >> n;
	FOR(i, 0, n) cin >> ar[i], ps[i] = (i == 0 ? 0 : ps[i-1]) + ar[i];
	ps[n] = ps[n-1];
}

i64 rs(int s, int e) {
	if(e < 0) return 0;
	return ps[e] - (s == 0 ? 0 : ps[s-1]);
}

i64 gettour1(i64 x) {
	if(x == 0) return 2;
	if(x % 2) return 1;
	return 0;
}

i64 getstr(i64 x) {
	if(x == 0) return 1;
	if(x % 2) return 0;
	return 1;
}

int solve() {
	FOR(i, 0, n) {
		t1[i] = min((i == 0 ? 0 : t1[i-1]) + gettour1(ar[i]), rs(0, i-1) + ar[i]%2); // 이전꺼까지 투어하던가, 여기서 끊던가
	}
	RFOR(i, n-2, 0) {
		t2[i] = min(t2[i+1] + gettour1(ar[i+1]), rs(i+2, n) + ar[i+1]%2);
	}
	i64 ans = INF;
	FOR(i, 0, n) {
		// 이전에서 오는 경우 (직선)
		dp[i] = (i == 0 ? 0 : dp[i-1]) + getstr(ar[i]);
		// 새로 만들어지는 경우 (투어)
		dp[i] = min(dp[i], t1[i]);
		ans = min(ans, dp[i] + t2[i]);
	}
	cout << ans << ENDL;
	return 0;
}

// ................. main .................. //
void execute() {
	input(), solve();
}

int main(void) {
#ifdef LOCAL_BOOKNU
	freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	cin.tie(0), ios_base::sync_with_stdio(false);
	execute();
	return 0;
}
// ......................................... //

Measured memory_bytes: 8064