n=int(input()) a=map(int,input().split()) tmp=1 ans=0 for i in range(n-1): if a[i]==1: for j in range(i+1,n): if tmp==1 and a[j]==0: tmp=0 ans+=1 elif tmp==0 and a[j]==1: tmp=1 ans+=1 else : break print(ans)