Suppose you want to go from the park to the railway station, and do not
want to walk more than the required number of blocks. You also want to make your
way avoiding the underground passages, that would introduce extra delay. Your
task is to determine the number of different paths that you can follow from the
park to the station, satisfying both requirements.
The example in the picture illustrates a city with 4 E-W streets and 5 N-S streets. Three intersections are marked as unsafe. The path from the park to the station is 3 + 4 = 7 blocks long and there are 4 such paths that avoid the underground passages.
The first line of the input contains the number of East-West streets W and the number of North-South streets N. Each one of the following W lines corresponds to a East-West street (from 1 to W, in that order) and starts with the number u of unsafe intersections, On the same line are the numbers of u North-South streets corresponding to the unsafe intersections.
Streets are numbered from 1. You may assume that W,N lie between 1 and 1000 (inclusive).
1 4 5 0 1 2 2 3 5 0
4