#include <stdio.h>
int main(){
int land,ans=0,wall=0;
scanf("%d",&land);
int garden[land],flower[land];
for(int i=0;i<land;i++){
scanf("%d",&garden[i]);
flower[i]=1;
}
for(int i=0;i<land;i++){
flower[i]=0;
if(garden[i]==1){
wall++;
break;
}
}
for(int i=land-1;i>=0;i--){
flower[i]=0;
if(garden[i]==1){
wall++;
break;
}
}
if(wall==2){
for(int i=0;i<land;i++)if(garden[i]==1)flower[i]=0;
for(int i=0;i<land;i++)if(flower[i]==1)if(garden[i]==9)for(int j=i-1;j<=i+1;j++)flower[j]=0;
for(int i=0;i<land;i++)if(flower[i]==1)ans++;
}
printf("%d",ans);
}