#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){};
};

ll width(TreeNode* root){
  if(!root)return 0;
  
  queue<pair<TreeNode*,ll>>q;
  
  ll ans = 0;
  q.push({root,0});
  
  while(!q.empty()){
  	auto sz = q.size();
  	ll mmin = q.front().second;
  	ll first = 0; ll last =0;
  	for(int i = 0 ; i < sz;i++){
  		auto u =q.front().first;
  		auto d= q.front().second;
  		q.pop();
  		ll curr = d - mmin;
  		if(i == 0)first = curr;
  		if(i == sz-1)last = curr;
  		
  		if(u->left)q.push({u->left,2*curr+1});
  		if(u->right)q.push({u->right,2*curr+2});
  		
  		
  	}
  	ans = max(ans,last-first+1);
  }
  return ans;
}
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<<width(root);
	return 0;
}