from sys import stdin n, *a = map(int, stdin.read().split()) ans = 0 renzoku = 0 last = 1 for i in range(n-1): if a[i] == 1: if last == 1: renzoku = 0 renzoku += 1 else: if last == 0: renzoku = 0 ans += renzoku last = a[i] print("{}".format(ans))