using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace MinPro2019D
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var L = ss.Next(int.Parse);
            var A = ss.Next(long.Parse, L);

            var dp = new long[L + 1 , 5].ToJagged();

            for (var i = 0; i < L; i++)
            {
                for (var t = 0; t < 5; t++)
                {
                    dp[i + 1][t] = dp[i].Take(t + 1).Min();

                    if (t == 0 || t == 4)
                    {
                        dp[i + 1][t] += A[i];
                    }

                    if (t == 1 || t == 3)
                    {
                        dp[i + 1][t] += A[i] == 0 ? 2 : A[i] % 2;
                    }

                    if (t == 2)
                    {
                        dp[i + 1][t] += 1 - (A[i] % 2);
                    }
                }
            }

            sw.WriteLine(dp[L].Min());
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public static class Extensions
    {
        public static T[][] ToJagged<T>(this T[,] source)
        {
            var x = source.GetLength(1);
            var y = source.GetLength(0);
            var ret = new T[y][];

            for (var i = 0; i < y; i++)
            {
                ret[i] = new T[x];

                for (var j = 0; j < x; j++)
                {
                    ret[i][j] = source[i, j];
                }
            }

            return ret;
        }

        public static T[][] Transpose<T>(this T[][] source)
        {
            var x = source.Length;
            var y = source.Select(a => a.Length).Distinct().Single();
            var ret = new T[y][];

            for (var i = 0; i < y; i++)
            {
                ret[i] = new T[x];

                for (var j = 0; j < x; j++)
                {
                    ret[i][j] = source[j][i];
                }
            }

            return ret;
        }
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 38508