L = gets.to_i
A = L.times.map { gets.to_i }

dp = Array.new(L + 1) { Array.new(5, Float::INFINITY) }
dp[0][0] = 0

A.each_with_index do |a, i|
  5.times do |j|
    next if dp[i][j] == Float::INFINITY

    case j
    when 0
      nc0 = dp[i][j] + a
      dp[i + 1][0] = nc0 if dp[i + 1][0] > nc0

      nc1 = dp[i][j] + ((a == 0) ? 1 : a % 2)
      dp[i + 1][1] = nc1 if dp[i + 1][1] > nc1

      nc2 = dp[i][j] + (a + 1) % 2
      dp[i + 1][2] = nc2 if dp[i + 1][2] > nc2
    when 1
      nc1 = dp[i][j] + ((a == 0) ? 1 : a % 2)
      dp[i + 1][1] = nc1 if dp[i + 1][1] > nc1

      nc2 = dp[i][j] + (a + 1) % 2
      dp[i + 1][2] = nc2 if dp[i + 1][2] > nc2

      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    when 2
      nc2 = dp[i][j] + (a + 1) % 2
      dp[i + 1][2] = nc2 if dp[i + 1][2] > nc2

      nc3 = dp[i][j] + ((a == 0) ? 1 : a % 2)
      dp[i + 1][3] = nc3 if dp[i + 1][3] > nc3

      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    when 3
      nc3 = dp[i][j] + ((a == 0) ? 1 : a % 2)
      dp[i + 1][3] = nc3 if dp[i + 1][3] > nc3

      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    when 4
      nc4 = dp[i][j] + a
      dp[i + 1][4] = nc4 if dp[i + 1][4] > nc4
    end
  end
end

puts dp[L].min
