// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll dp[N][4];
ll a[N], n;
ll par[N];
int main(){
	IOS;
	cin >> n;
	memset(dp, 63, sizeof dp);
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		par[i] = a[i] + par[i - 1];
	}
	dp[1][0] = dp[1][1] = 0; 
	for (int i = 2; i <= n + 1; i++){
		if (a[i - 1] == 0){
			dp[i][0] = min(dp[i][0], dp[i - 1][0] + 2);
			dp[i][0] = min(dp[i][0], par[i - 1]);
			dp[i][1] = min(dp[i][1], dp[i][0]);
			dp[i][1] = min(dp[i][1], dp[i - 1][1] + 1);
		}else{
			if (a[i - 1] % 2 == 0){
				dp[i][0] = min(par[i - 1], dp[i - 1][0]);
				dp[i][1] = dp[i][0];
				dp[i][1] = min(dp[i][1], dp[i - 1][1] + 1);
			}else{
				dp[i][0] = min(par[i - 1] + 1, dp[i - 1][0] + 1);
				dp[i][1] = dp[i][0];
				dp[i][1] = min(dp[i][1], dp[i - 1][1]);
			}
		}
	}	
	dp[n + 1][2] = dp[n + 1][3] = 0;
	for (int i = n; i > 0; i--){
		if (a[i] == 0){
			dp[i][2] = dp[i + 1][2] + 2;
			dp[i][2] = min(dp[i][2], par[n] - par[i - 1]);
			dp[i][3] = dp[i][2];
			dp[i][3] = min(dp[i][3], dp[i + 1][3] + 1);
		}else{
			if (a[i] % 2 == 0){
				dp[i][2] = dp[i + 1][2];
				dp[i][2] = min(dp[i][2], par[n] - par[i - 1]);
				dp[i][3] = dp[i][2];
				dp[i][3] = min(dp[i][3], dp[i + 1][3] + 1);
			}else{
				dp[i][2] = dp[i + 1][2] + 1;
				dp[i][2] = min(dp[i][2], par[n] - par[i - 1] + 1);
				dp[i][3] = dp[i][2];
				dp[i][3] = min(dp[i][3], dp[i + 1][3]);
			}
			
		}
	}
	ll Min = INF;
	for (int i = 1; i <= n + 1; i++){
		Min = min(Min, min(dp[i][0] + dp[i][3], dp[i][2] + dp[i][1]));
	}
	cout << Min;
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




Measured memory_bytes: 9600