Lethargic Lumen
InterviewTime limit1sMemory limit1024 MB
Given an acyclic undirected graph with n nodes, add edges to make it a tree and print the smallest possible diameter.
Statement
Pogi spends his days watching undirected graphs without cycles.
Pogi wants to turn one such graph with nodes and edges into a tree. He adds some edges, and he wants the resulting tree to have the smallest possible diameter.
A tree on nodes is a connected undirected graph with nodes and no cycles.
The diameter of a tree is the maximum distance between any two nodes in it.
Help Pogi, since he is a good person and does not want trouble.
Input
The first line contains natural numbers () and () from the problem text.
The next lines each contain two natural numbers that describe an edge of the initial graph.
The node labels are integers from to .
Output
Print the smallest possible diameter of the tree on a single line.