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