def DFS(maze,V):
global Visit
global Depth
Visit[V]=1
for i in range(len(maze)):
if maze[V][i]==1 and Visit[i]==0:
Depth[i] = Depth[V]+1
DFS(maze, i)
def Leaf(Maze):
count=0
leaf = []
for i in range(len(Maze)):
for j in Maze[i]:
if j == 1:
count+=1
if count==1:
leaf.append(i)
count=0
return leaf
def main(n, maze):
global Visit
global Depth
leaf = []
ADep = []
Visit = [0]*n
Depth = [1]*n
leaf = Leaf(maze)
for i in leaf:
for a in range(len(maze)):
Visit[a] = 0
for j in range(len(maze)):
Depth[j] = 1
DFS(maze,i)
ADep.append(max(Depth))
return max(ADep)-1
result = []
while True:
try:
n = int(input())
maze = [[0]*n for i in range(n)]
for i in range(n-1):
temp = list(map(int, input().split()))
maze[temp[0]][temp[1]] = 1
maze[temp[1]][temp[0]] = 1
result.append(main(n, maze))
except ValueError or EOFError:
break
for i in result:
print(i)