n = gets.strip.to_i
a= gets.strip.split.map(&:to_i)

def dfs(arr)

  body = arr[1..-2]
  return arr.inject(:+) if body.empty?
  body.map.with_index {|x, index|
    target_index = index+1
    c_arr = arr.dup

    c_arr[target_index-1]+=x
    c_arr[target_index+1]+=x
    c_arr[target_index]=nil
    dfs(c_arr.compact)
  }.min
end

p dfs(a)
