Comparing Code

No attempts yetTime limit1sMemory limit128 MB

Problem

Two companies, RBN and HAL, both use a programming language with one statement per line. Every statement has the form

STOREA = STOREB + STOREC

where STOREA, STOREB, and STOREC are variable names. That is, each line consists of a variable name starting in the first column, followed by a space, an equals sign, a space, a second variable name, a space, the addition symbol +, a space, and a third variable name. The same variable name may appear more than once on a single line. Variable names consist of $1$ to $8$ uppercase letters (AZ).

Suppose HAL copied a consecutive block of lines directly from RBN's source code, making only the following minor modifications:

  • HAL may have renamed some variables. That is, HAL took a consecutive block of lines from RBN's program and, for each variable in it, changed every occurrence of that variable to a new variable name (the new name may equal the original). No two distinct variables were renamed to the same new name (the renaming is injective).
  • HAL may have swapped the two right-hand operands of some lines: STOREA = STOREB + STOREC may have become STOREA = STOREC + STOREB.
  • HAL did not change the order of RBN's lines.

Given RBN's program and HAL's program, find the length of the longest consecutive block of lines in HAL's program that could have been produced from a consecutive block of lines in RBN's program using the modifications above. The two corresponding blocks need not start at the same line number.

Input

The first line contains two space-separated integers $R$ and $H$ ($1 \le R \le 1000$, $1 \le H \le 1000$). $R$ is the number of lines in RBN's program and $H$ is the number of lines in HAL's program.

The next $R$ lines contain RBN's program.

The next $H$ lines contain HAL's program.

Output

Print a single integer on one line: the length of the longest consecutive block of lines HAL could have copied from RBN and transformed. (Print $0$ if there is no such block.)

Note

In the sample, applying the substitutions RA → HM, RB → D, RC → HN, D → HA, RE → HB to RBN's program makes lines 1–2 of RBN identical to lines 2–3 of HAL. No block of three or more lines matches, so the answer is $2$.