All problems

Problem 638

Maximal Network Rank

Medium · 20 pts · Graph

Problem

N cities are connected by roads, with at most one road between any two cities. The network rank of two different cities is the number of roads connected to either of them; a road that connects the two cities themselves is counted only once. Find the maximal network rank over all pairs of different cities. For each pair, the rank is degree(a) + degree(b), minus 1 if a and b are directly connected.

Input

The first line contains N and M. Each of the next M lines contains a road u v.

Output

Print the maximal network rank.

Constraints

2 <= N <= 100; 0 <= M <= N × (N - 1) / 2

Example input

4 4
1 2
1 4
2 3
2 4

Example output

4

Explanation

With roads 1-2, 1-4, 2-3 and 2-4, city 1 has 2 roads and city 2 has 3. They share the road 1-2, so their rank is 2 + 3 - 1 = 4, the largest of all pairs.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Minimum Fuel Cost to Report to the Capital Next: Checking Existence of Edge Length Limited Paths