import java.util.Scanner; public class No1765 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int[] A = new int[N-1]; for (int i=0; i < N-1; i++) { A[i] = scan.nextInt(); } scan.close(); int m0 = 0, m1 = 0, cnt = 0; for (int a : A) { if (a == 1) { cnt += 1 + m1; m0 = 1 + m1; m1 = 0; } else { cnt += m0; m1 = m0; m0 = 0; } } System.out.println(cnt); } }