#include <bits/stdc++.h>
using namespace std;

using ll = long long;

struct TreeNode{
	int val;
	TreeNode* left;
	TreeNode* right;
	
	TreeNode(int val):val(val),left(nullptr),right(nullptr){};
};

int dep(TreeNode* root){
    int d = 0;
    while(root){
        root = root->left;
        d++;
    }
    return d;
}
    int countNodes(TreeNode* root) {
        if(!root)return 0;
        int l = dep(root->left);
        int r = dep(root->right);

        if(l == r){
            return (1<<l)+countNodes(root->right);
        }else{
            return (1<<r)+countNodes(root->left);
        }
       // return 1+max(l,r);
    }

TreeNode* buildTree(){
	int x; cin>>x;
	if(x == -1)return nullptr;;
	
	TreeNode* root = new TreeNode(x);
	queue<TreeNode*>q;
	q.push(root);
	
	while(!q.empty()){
		auto u = q.front();
		q.pop();
		
		if(cin>>x && x!=-1){
			u->left = new TreeNode(x);
			q.push(u->left);
		}
		
			if(cin>>x && x!=-1){
			u->right = new TreeNode(x);
			q.push(u->right);
		}
	}
	return root;
}

int main() {
TreeNode* root = buildTree();
cout<<countNodes(root);


	return 0;
}