#include <bits/stdc++.h>
using namespace std;
struct TreeNode{
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode(int val):left(nullptr),right(nullptr),val(val){};
};
int height(TreeNode* root){
	int cnt = 0;
	if (root == nullptr){
		return 0;
	}
	
	queue<TreeNode*>q;
	q.push(root);
	
	while(!q.empty()){
		int size = q.size();
		for(int i = 0;i<size;i++){
		auto u = q.front();
		q.pop();
		
		if(u->left){
			q.push(u->left);
		}
		if(u->right){
			q.push(u->right);
		}
		}
		cnt++;
	}
	return cnt;
}
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();
	int h = height(root);
	cout<<h;
	return 0;
}