#P6479. Singing in the Village

    ID: 19693 Type: Default 1000ms 256MiB

Singing in the Village

Singing in the Village

A small village has nn villagers numbered from 11 to nn, where villager 11 is a poet. Every evening, some villagers gather around a campfire to sing. There are two cases for each evening:

  1. 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.

  2. 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 mm 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 nn and the total number of songs composed by the poet is denoted by totalSongstotalSongs.

inputFormat

The first line contains two integers nn and mm, representing the number of villagers and the number of evenings, respectively. Each of the following mm lines starts with an integer kk, indicating the number of villagers present on that evening, followed by kk 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