#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int data;
struct node *lchild,*rchild;
}treenode;
int cretree(treenode* &root){
int x;
cin>>x;
if(x==0) root=NULL;
else{
root=new treenode;
root->data=x;
cretree(root->lchild);
cretree(root->rchild);
}
return 0;
}//1 2 3 0 0 4 5 0 6 0 0 7 0 0 0
int getdepth(treenode *root){
if(root==NULL) return 0;
int m,n;
m=getdepth(root->lchild);
n=getdepth(root->rchild);
return max(m,n)+1;
}
int main()
{
int n;
treenode *root;
cretree(root);
n=getdepth(root);
cout<<n<<endl;
return 0;
}