n = int(input()) a = list(map(int,input().split())) ans = 0 flg = a[0] i = 0 while i <= n-2: if a[i] == 1 and a[i+1] == 0: cnt +=2 ans += cnt i += 2 else: if a[i] == 1: ans += 1 + cnt//2 cnt = 0 i += 1 # print(ans) print(ans)