#include <bits/stdc++.h>
using namespace std;
struct TreeNode{
	int val;
	TreeNode*right;
	TreeNode*left;
	TreeNode(int val):left(nullptr),right(nullptr),val(val){};
};
int height(TreeNode* root){
	if(root == nullptr)return 0;
	return 1+ max(height(root->right),height(root->left));
}
int diameter(TreeNode*root){
	if(root == nullptr)return 0;
	
	int l = height(root->left);
	int r = height(root->right);
	
	int ld = diameter(root->left);
	int rd = diameter(root->right);
	
	return max(l+r,max(ld,rd));
}
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<<diameter(root);
	return 0;
}