n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(n-1): tmp=1 if a[i]==1: ans+=1 for j in range(i+1,n-1): 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)