a=int(input())
b=list(map(int,input().split()))
c=b.count(1)
if c<2:
print(0)
else:
sw=1
for i in range(a-1):
if b[i]==1:
c=c-1
sw=0
if c==0:
break
if sw==0:
if b[i]==9:
if b[i+1]!=9 and b[i+1]!=1:
b[i+1]=8
b[i-1]=8
else:
b[i]=8
d=i
b=b[0:d+1]
print(b.count(0))