$edge=([0]*101).map{[0]}
$size=[0]*101
$used=[false]*101
def rec idx
ret=1
$size[idx].times{|i|
i-=1
if !$used[$edge[idx][i]]
$used[$edge[idx][i]]=true
ret=[ret,rec($edge[idx][i])+1].max
$used[$edge[idx][i]]=false
end
}
ret
end
while(n=gets.to_i)>0
n.times{
a,b=gets.split.map &:to_i
a-=1
b-=1
$edge[a][$size[a]+=1]=b
$edge[b][$size[b]+=1]=a
}
ret=0
100.times{|i|
i-=1
$used[i]=true
ret=[ret,rec(i)].max
$used[i]=false
}
p ret
end