def f h,n,e
e.include?(n)&&0||h[n].map{|a|1+f(h,a,e+[n])}.max||0
end
while(n=gets.to_i)>0
h=([0]*101).map{[]}
n.times{a,b=gets.split.map &:to_i;h[a]<<b;h[b]<<a}
ret=1
(1..100).map{|i|
s=[[i,0]]
u=[i]
while(s!=[])
j,k=s.pop
l=h[j][k]
if !l
  u.pop
elsif u.include? l
    s<<[j,k+1]
  ret = [ret,u.size].max
else
    s<<[j,k+1]
    u<<l
    s<<[l,0]
end
end
}

p ret
end