A new circular zoo, the pride of the Asia-Pacific region, has just been built on a small island in the Pacific. Its animal cages are arranged in one big circle, and each cage holds a single, distinct animal.
The goal is to make as many visiting children as possible enjoy their visit. This is not easy: some children love certain animals while others are frightened by them. For example, Alex loves monkeys and koalas because they are cute but is scared of lions because of their sharp teeth, while Polly loves lions for their beautiful manes but dislikes koalas because of their awful smell.
We may move some of the animals that children fear to another zoo (that is, empty those cages). But moving too many is bad, because then there would be nothing left to look at. We want to choose which animals to move so that as many children as possible are happy.
Each child stands outside the circle and watches only the animals in the 5 consecutive cages directly in front of them. For each child, the list of animals they fear and the list they like are given. A child is happy if at least one of the following holds:
For example, suppose five children are described by the table below.
| Child | Watched cages | Feared cages | Liked cages |
|---|---|---|---|
| Alex | 2, 3, 4, 5, 6 | 4 | 2, 6 |
| Polly | 3, 4, 5, 6, 7 | 6 | 4 |
| Chaitanya | 6, 7, 8, 9, 10 | 9 | 6, 8 |
| Hwan | 8, 9, 10, 11, 12 | 9 | 12 |
| Ka-Shu | 12, 13, 14, 1, 2 | 12, 13, 2 | (none) |
Find the maximum number of children that can be happy at the same time.
The first line contains two integers $N$ and $C$. $N$ ($10 \le N \le 10000$) is the number of cages and $C$ ($1 \le C \le 50000$) is the number of children. The cages are numbered $1, 2, \ldots, N$ clockwise around the circle.
Then $C$ lines follow, each describing one child's watched cages, feared animals, and liked animals in the following format.
E F L X1 X2 ... XF Y1 Y2 ... YL
where:
$X_1, \ldots, X_F, Y_1, \ldots, Y_L$ are all distinct, and every one of them is a cage that this child watches.
The children are given in nondecreasing order of $E$ (the child with the smallest $E$ first, the largest $E$ last). Note that two or more children may share the same value of $E$.
Print a single integer: the maximum number of children that can be happy at the same time.