Under construction

Still being built. Things may change

Tail of a Graph

Interview

Time limit2sMemory limit1024 MB

Summary
Given a connected undirected graph, find the number of vertices in the longest tail, a path whose inner vertices have no neighbors outside the path.
Level

Medium4 of 10

Topics
Graph, BFS, Implementation
Solved
No attempts yet

Statement

Petya has loved kites since childhood. He enjoys watching them fly, especially how the tail of a kite ripples in the wind. In a math lesson, which he also likes, the teacher drew a graph shaped like a kite on the board as an example. Petya immediately noticed the tail of the graph.

We call a tail of a graph a sequence of connected vertices such that the first vertex is connected only to the second, the second is connected only to the first and the third, and each later vertex is connected only to its neighbors in the sequence. The last vertex may be connected only to the penultimate vertex, or to the penultimate vertex and to a vertex that is not part of the tail.

Petya has a new hobby: finding the longest tail in a graph. The length of a tail is the number of vertices in it. Petya cannot always work out the length of a tail yet. Please help him.

Input

The first line of the input file contains two integers nn (1≤n≤1000001 \le n \le 100000), the number of vertices in the graph, and mm (1≤m≤2000001 \le m \le 200000), the number of edges. Each of the next mm lines contains two integers ai,bia_i, b_i, the numbers of the vertices connected by the corresponding edge.

Each pair of vertices is connected by at most one edge, and no edge connects a vertex to itself. Every vertex has a path to every other vertex in the graph.

Output

Print one integer to the output file, the length of the longest tail of the graph.

Examples1

  1. Example 1

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