The evil mage storms into his throne room. The heroes have raided his cave again, and they picked the week the traps were switched off for maintenance. Worse, they have pitched camp inside. The traps are live again, and the mage wants his trained orcs teleported to the right places right now. You saw what happened to the last servant who spoke, so you grab the map of the cave and get to work.
The map shows $n$ strategic key points, numbered $1$ to $n$. Every passage connects two key points, every trap sits on a key point, and every dead end is a key point. No key point has more than three passages. Key point $1$ is the entrance to the outside world and has exactly one passage. From every key point there is exactly one path to the entrance. A key point with exactly one passage is a dead end, with key point $1$ as the only exception.
Your master opens a magic gateway in the middle of a passage, never at a key point, and an orc walks out of it. The orc first heads in the direction that leads away from the light of the entrance. From there it walks by these rules.
Left and right are seen from the orc as it walks, which is why the map lists the passages of a key point in clockwise order.
You may give the orc one number $t$ before it walks in. The $t$-th time it stands at an intersection it takes the passage on its right instead of the left one. An orc remembers a single number until it comes back, so it turns right at most once per trip. You may send orcs through the same gateway one after another, each with its own number, and a gateway stays open as long as you need it.
An orc that steps on a key point with a trap is lost, and your master will not forgive that. Every orc also has to come back to its gateway, so choose $t$ accordingly.
The heroes camp in a dead end, so the orcs have to search every dead end that reaches the entrance without passing a trap. A dead end has to be searched when no key point on the path from it to the entrance holds a trap, the dead end itself included. Your master should open as few gateways as possible.
The input consists of several data sets. Each set starts with a line holding two integers $n$ and $m$, where $2 \le n \le 50000$ is the number of key points and $0 \le m \le 500$ is the number of traps.
The next $n$ lines describe the key points. Line $i$ holds an integer $n_i$ with $1 \le n_i \le 3$, the number of passages at key point $i$, followed by the $n_i$ key points those passages lead to, listed in clockwise order.
The next $m$ lines hold one integer each, a key point that has a trap.
Key point $1$ is the entrance and always has exactly one passage. The last data set is followed by a line holding $0$ $0$, which is not processed.
For each data set, print the minimum number of gateways on a line by itself.