Game Map

Given an undirected connected graph, find the longest simple path where the degree of each successive vertex strictly increases.

Medium6GraphDynamic programmingSortingDFSInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

ICPC-World is a role playing game whose goal is to conquer the world. A game map consists of several cities. Between any two cities there is at most one road, and every road is bidirectional. Two cities joined by a road are called neighbors. Every city has one or more neighbors, and all cities are reachable from each other along the roads. A player may start at any city. After conquering the city where the player stands, the player moves to one of its neighbors and conquers that city at the next stage.

Chansu fixes the list of cities he will conquer before he starts the game. This time he wants to choose as many cities as possible while keeping the conditions below. Let (c0,c1,,ck1)(c_0, c_1, \ldots, c_{k-1}) be the list in conquest order.

  • All cities in the list are distinct, that is, cicjc_i \neq c_j whenever iji \neq j.
  • cic_i and ci+1c_{i+1} are neighbors.
  • The number of neighbors of ci+1c_{i+1} is greater than the number of neighbors of cic_i.

The last two conditions must hold for every i=0,1,,k2i = 0, 1, \ldots, k-2.

For example, look at the map in the figure below. It has six cities and nine roads: 0-1, 0-4, 1-2, 1-3, 1-4, 1-5, 2-5, 3-4, 4-5. City 0 has two neighbors and city 1 has five neighbors. The longest list that satisfies the conditions is (2,5,4,1)(2, 5, 4, 1), which conquers four cities.

Example map with six cities

Given a game map with nn cities, write a program that finds the maximum number of cities Chansu can conquer, that is, the length of the longest list satisfying the conditions.

Input

The first line contains the number of cities nn and the number of roads mm (1n100,0001 \le n \le 100{,}000, n1m300,000n-1 \le m \le 300{,}000). The cities are numbered from 00 to n1n-1. Each of the next mm lines contains two integers ii and jj, the cities joined by one road (0ijn10 \le i \neq j \le n-1).

Output

Print the maximum number of cities Chansu can conquer on one line. A list holding a single city already satisfies the conditions, so the answer is always at least 11.