n = gets.to_i
a = gets.split.map(&:to_i)
h = {}
(0..a[0]).each {|i| h[i] = a[0] - i}
a[1..-1].each do |c|
    new_h = Hash.new(Float::INFINITY)
    h.each do |r, m|
        if r > c
            k = m + 2 * r
            new_h[0] = k if k < new_h[0]
        else
            (r..c).each do |t|
                k = m + 2 * t
                new_h[c-t] = k if k < new_h[c-t]
            end
        end
    end
    h = new_h
end
p h.map {|r, m| r + m}.min
