const main = (input) => {
  const N = input[0]-0;
  var list = input[1].split(" ").map(v=>v-0);


  var stack = [list];
  var ans = Number.MAX_VALUE;
  while(stack.length > 0){
    list = stack.shift();
    if(list.length == 2){
      ans = Math.min(ans, list[0] + list[1]);
    }
    var objs = [];
    for(var n=1;n<list.length-1;n++){
      var next = del(list, n);
      var nextsum = 0;
      var nextvsum = 0;
      next.forEach((v, i)=>{
        nextsum+=v;
        if(i!=0 || i!=next.length-1) nextvsum+=v;
      });
      objs.push({
        next:next,nextsum :nextsum ,nextvsum:nextvsum,
      });
    }
    objs.sort((a,b)=>a.nextsum-b.nextsum)
    .forEach((v,i)=>{
      if(objs[0].nextsum < ans ){
        stack.push(v.next);
      }
    });
  }
  console.log(ans);
}

function del(list, mini){
  var minv = list[mini];
  var t_list = list.filter((v,i)=>{
    return i!=mini;
  });
  t_list[mini-1]+=minv;
  t_list[mini]+=minv;
  return t_list;
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));
