Under construction

Still being built. Things may change

Lethargic Lumen

Interview

Time limit1sMemory limit1024 MB

Summary
Given an acyclic undirected graph with n nodes, add edges to make it a tree and print the smallest possible diameter.
Level

Medium5 of 10

Topics
Graph, Tree, BFS, Greedy
Solved
No attempts yet

Statement

Pogi spends his days watching undirected graphs without cycles.

Pogi wants to turn one such graph with nn nodes and mm edges into a tree. He adds some edges, and he wants the resulting tree to have the smallest possible diameter.

A tree on nn nodes is a connected undirected graph with nn 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 nn (1≤n≤100 0001 \le n \le 100\,000) and mm (0≤m≤m−10 \le m \le m - 1) from the problem text.

The next nn lines each contain two natural numbers that describe an edge of the initial graph.

The node labels are integers from 00 to n−1n - 1.

Output

Print the smallest possible diameter of the tree on a single line.

Examples2

  1. Example 1

    Input
    6 4
    0 1
    0 2
    3 4
    3 5
    
    Expected output
    3
    
  2. Example 2

    Input
    11 9
    0 1
    0 3
    0 4
    1 2
    5 4
    6 4
    7 8
    7 9
    7 10
    
    Expected output
    4