var
ans,n,b,c,d:longint;
a,p:array[1..10000000]of longint;
begin
assign(input,'zdota.in');
assign(output,'zdota.out');
reset(input);
rewrite(output);
read(n);
for n:=1 to n do read(p[n]);
a[2]:=p[1];
a[3]:=p[2];
if a[2]>a[3] then a[4]:=a[3]+p[3] else a[4]:=a[2]+p[3];
for b:=5 to n+1 do
begin
d:=a[b-3];
for c:=b-2 to b-1 do
if a[c]<d then d:=a[c];
a[b]:=d+p[b-1];
end;
if a[n]<a[n+1] then ans:=a[n] else ans:=a[n+1];
writeln(ans);
close(input);
close(output);
end.