Domain clusters

Given a directed graph of domains, find the size of the largest set in which every domain can reach every other domain.

Medium6GraphDFSImplementationMathInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

We analyze how the domains on the Internet link to each other. A domain is the part of a URL that comes before the / character. twitter.com, aipo.computing.dcu.ie, and google.com are domains.

A domain d1 is connected to a domain d2 if there is a link from d1 to d2, or if d1 is connected to a domain d3 and d3 is connected to d2. Every domain is connected to itself.

The picture below shows a structure of five domains. Its links go from D1 to D2, D1 to D4, D2 to D3, D3 to D2, D3 to D4, D3 to D5, and D5 to D2.

a structure of five domains joined by seven links

  • D1 is connected to D2, D3 (through D2), D4, and D5 (through D3).
  • D2 is connected to D3, D4 (through D3), and D5 (through D3).
  • D3 is connected to D2, D4, and D5.
  • D4 is not connected to any other domain.
  • D5 is connected to D2, D3 (through D2), and D4 (through D3).

We want the largest set of domains SS in which every domain is connected to all the other domains of SS. In the structure above the sets that meet this criterion are:

  • {D1}: connected to itself.
  • {D2, D3, D5}: D2 reaches D3 and D5, D3 reaches D2 and D5, and D5 reaches D2 and D3.
  • {D4}: connected to itself.

Given the links of the Internet, compute the size of the largest such set.

Input

The first line contains an integer DD, the number of domains. The names of the domains are the integers from 11 to DD. (1D50001 \le D \le 5000)

The second line contains an integer LL, the number of links between domains. Each of the following LL lines contains two integers. The first integer is the source of the link and the second is the destination. A link from A to B does not imply a link from B to A, and every domain is connected to itself without an explicit link. No link appears more than once. (0LD20 \le L \le D^2)

Output

Print the size of the largest set of domains that meets the criterion above. If two or more sets tie for the largest size, print that size once.