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).each{|i|
if h[i]!=[]
s=[0]
u=[i]
while(s!=[])
j=u[-1]
k=s[-1]
while 1
l=h[j][k]
if !l
  s.pop
  u.pop
  break
elsif u.include? l
  ret = u.size if ret<u.size
  k+=1
else
  s[-1]=k+1
  u<<l
  s<<0
  break
end
end
end
end
}

p ret
end