#include <bits/stdc++.h>
using namespace std;
struct TreeNode{
	int val;
	vector<TreeNode*>child;
	TreeNode(int val):child({}),val(val){};
};
TreeNode* constructTree(vector<int>&arr){
if(arr[0]==-1)return nullptr;
TreeNode* root = new TreeNode(arr[0]);

stack<TreeNode*>st;
st.push(root);

for(int i = 1;i<arr.size();i++){
	if(arr[i]!=-1){
		TreeNode* par = st.top();
		TreeNode* newChild = new TreeNode(arr[i]);
		par->child.push_back(newChild);
		st.push(newChild);
	}else{
		st.pop();
	}
}
return root;
}
int height(TreeNode* root){
	if(!root )return -1;
//	if(!root->child)return 1;
	//int mx = root->val;
	int mx = -1;
	for(auto child: root->child){
	int maximum = height(child);
	 mx = max(maximum,mx);
	}
	return 1+mx;
}
void displayTree(TreeNode* root){
	if(root)cout<<root->val<<"->";
	
	for(auto child : root->child)cout<<child->val<<",";
	cout<<"."<<endl;
	for(auto child : root->child)displayTree(child);
}
int main() {
	//-1 for going up to the par then down to its next child
//vector<int>arr = {10,20,50,-1,60,-1,-1,30,70,-1};
vector<int>arr = {10,20,50,-1,60,-1,-1,30,70,-1,80,100,-1,110,-1,-1,90,-1,-1,40,120,-1,130,-1,-1,-1};
	TreeNode* root = constructTree(arr);
	//displayTree(root);
	cout<<height(root);
	return 0;
}