#include <stdio.h>
#include <stdlib.h>

typedef struct tT {int zn; struct tT *left;struct tT *right;}TREE;

void Insert(TREE **root, int x)
  {
    TREE *newel;
    
  if (*root == NULL)
    { 
      newel = (TREE*)malloc(sizeof(TREE));
      newel->zn = x;
      newel->left = newel->right = NULL;
	*root=newel;
    }
  else
    {
     if (x < (*root)->zn)
	Insert(&((*root)->left), x);
      else if (x > (*root)->zn)
	Insert(&((*root)->right), x);
    }
  }
  
int Vis(TREE *root)
{
	int l,r;
	if (root == NULL) return 0;
	else
	{	
		l = 1 + Vis(root->left);
		r = 1 + Vis(root->right);
		if (l > r) return l;
		else return r;
	}
}

TREE* DestroyTree(TREE *root)
  { 
    
  if (root != NULL )
    { if (root->left != NULL)
	root->left = DestroyTree(root->left);
      if (root->right != NULL)
	root->right = DestroyTree(root->right);
      free(root);
    }

  return NULL;

  }
  

int main()
  {
   int n;
   TREE *mtree = NULL;
   
   scanf("%d",&n);
   while (n !=0)
    {
      Insert(&mtree, n);
      scanf("%d",&n);
    }
    printf("%d\n", Vis(mtree));
    if (mtree != NULL) mtree = DestroyTree(mtree);
   
   return 0;
  }
  
