#include<stdio.h>
int a[1000010]={0},f[1000010]={0};
int min(int x,int y){return x<y?x:y;}
int _521()
{
freopen("zdota.in","r",stdin);
freopen("zdota.out","w",stdout);
int i,j,k,n;
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
f[0]=f[1]=a[1],f[2]=a[2];
f[3]=min(f[1]+a[3],f[2]);
for(i=3;i<=n;i++)
f[i]=a[i]+min(min(f[i-3],f[i-2]),f[i-1]);
printf("%d\n",min(f[n],f[n-1]));
return 0;
}
int _520=_521();
int main(){;}