eolymp
bolt
Try our new interface for solving problems
Problems

Nature

Nature

In nature, there are alimentary chains. At the basis of this chain, we generally have the vegetals. Small animals eat those vegetals and bigger animals eat the smaller. There can be cycles in the chain, as when some animal dies he starts a decomposition process which will transform its body into minerals that are a source of energy for the vegetals. In this problem you will have to find the largest alimentary chain for a given group of creatures. You can consider that if $A$ is predator of $B$ then they are in the same chain. \InputFile Contains several input sets. The description of each set is given below: \begin{itemize} \item each set starts with two integers $c~(1 \le c \le 5000)$, the number of creatures, and $r~(0 \le r \le 5000)$, the number of relations. Follow $c$ lines with the names of the creatures, each consisting of lower case letters $(a, b, ..., z)$. No name is longer than $30$ letters. Then there will be $r$ lines describing the relations. Each line will have $2$ names of creatures, meaning that the second creature is a predator of the first one. \end{itemize} You can assume that no creature is a predator of himself. Input is terminated by a set where $c = r = 0$. This set should not be processed. There is a blank line beteween two input sets. \OutputFile For each input set produce one line of output, the size of the largest alimentary chain.
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 2
caterpillar
bird
horse
elefant
herb
herb caterpillar
caterpillar bird

0 0
Output example #1
3