#P6479. Singing in the Village
Singing in the Village
Singing in the Village
A small village has villagers numbered from to , where villager is a poet. Every evening, some villagers gather around a campfire to sing. There are two cases for each evening:
-
If the poet is present, he composes a new song that no one has heard before and teaches it to everyone present. On that evening, no other song is sung.
-
If the poet is absent, the villagers present sing all the songs that at least one of them knows, and they share these songs with those among them who do not yet know them.
Initially, no one knows any songs and the poet has composed no songs. After evenings, output how many villagers know every song composed by the poet.
Note: All formulas are in (\LaTeX) format. For example, the number of villagers is denoted by and the total number of songs composed by the poet is denoted by .
inputFormat
The first line contains two integers and , representing the number of villagers and the number of evenings, respectively. Each of the following lines starts with an integer , indicating the number of villagers present on that evening, followed by integers representing their IDs.
outputFormat
Output a single integer: the number of villagers who know all the songs composed by the poet.
sample
4 3
2 1 2
3 2 3 4
2 1 4
2