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

typedef struct gg {int num; struct gg *L; struct gg *R;} PTree;

void Add(PTree **t, int n)
{
	PTree *p;
	if (*t == NULL)
	{
		p = (PTree*)malloc(sizeof(PTree));
		p->num = n;
		p->L = NULL;
		p->R = NULL;
		*t = p;
	}	
	else
	{
		if (n > (*t)->num) 
			Add(&((*t)->R), n);
		if (n < (*t)->num) 
			Add(&((*t)->L), n);
	}
}

int Height(PTree *t)
{
	int l,r;
	if (t == NULL) return 0;
	else
	{	
		l = 1 + Height(t->L);
		r = 1 + Height(t->R);
		if (l > r) return l;
		else return r;
	}
}

int Destroy(PTree *t)
{
	if (t != NULL)
	{
		Destroy(t->L);
		Destroy(t->R);
		free(t);
	}
}


int main()
{
	PTree *tr=NULL;
	int k;
	scanf("%d", &k);
	while (k != 0)
	{
		Add(&tr, k);
		scanf("%d", &k);
	}
	printf("%d\n", Height(tr));
	Destroy(tr);
	return 0;
}
