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

struct TreeNode{
	int val;
	TreeNode* left;
	TreeNode* right;
	
	TreeNode(int val):val(val),left(nullptr),right(nullptr){};
};
int width(TreeNode* root){
	if(root==nullptr)return 0;
	queue<pair<TreeNode*,int>>q;
	q.push({root,0});
int ans = 0;


	while(!q.empty()){
		int size = q.size();
		int mmin = q.front().second;
		int first = -1,last =-1;
		for(int i = 0 ; i < size;i++){
			auto node=q.front();
		q.pop();
		auto u = node.first;
		
		int cur_id = node.second - mmin;
			if(i == 0)first = cur_id;
			if(i == size-1)last = cur_id;
			//cout<<"first"<<first<<endl;
		//	cout<<"last"<<last<<endl;
			if(u->left)q.push({u->left,2*cur_id+1});
			if(u->right)q.push({u->right,2*cur_id +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)<<endl;
	return 0;
}