/* package whatever; // don't place package name! */

import java.util.*;
class Main{
	static class Node{
		Node right;
		Node left;
		int data;
		Node(int data){
			this.data = data;
		}
	}
	static Node buildtree(int[]vals){
		if(vals.length == 0 || vals[0] == -1) return null;
		Node root = new Node(vals[0]);
		Queue<Node> q = new LinkedList<>();
		q.offer(root);
		int i = 1;
		while(!q.isEmpty() && i<vals.length){
			Node curr = q.poll();
			if(i<vals.length && vals[i]!= -1){
				curr.left = new Node(vals[i]);
				q.offer(curr.left);
			}i++;
			if(i<vals.length && vals[i]!= -1){
				curr.right = new Node(vals[i]);
				q.offer(curr.right);
			}i++;
		}
		return root;
	}
	static int find(Node root){
		if(root == null) return 0;
		if(root.left!=null && root.right!=null) return 1;
		// if(root.left==null && root.right!=null) return 1;
		
		int count = find(root.left)+find(root.right);
		
		return count;
	}
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++){
			arr[i] = sc.nextInt();
		}
		Node root = buildtree(arr);
		System.out.println(find(root));
	}
}