Problem D

Meeting Rooms Management

An important institution needs to manage the meeting rooms in its headquarters. The members of the institution may reserve the meeting rooms. Each reservation lasts for a complete day. For each meeting room, it is only possible to accept one reservation request for each day.

When someone submits a reservation request, it is possible to specify a set of alternative scheduling details. Each scheduling details includes the identifier of the meeting room to reserve and the day in which it should be reserved. The identifier of the meeting room is an integer from 1 to the number of existent meeting rooms.

A reservation request is accepted if it is possible to make a reservation according to one of the alternative scheduling details. For each reservation request, only one meeting room reservation should be executed (from the set of alternative scheduling details).

Problem

Write a program that, given the number of existent meeting rooms and a set of reservation requests, computes the maximum number of requests that can be accepted.

Input

The first input line contains an integer n, which specifies the number of meeting rooms that exist.

The second line of the input contains an integer j, which indicates the number of requests that follow. Each request is described as follows.

The first line contains an integer k (0 < k < 10), which specifies the number of alternative scheduling details in the request.

Each of the next k lines contains the scheduling details of a single alternative, which are given by four integers r, d, m, and y, separated by a single space.

Integer r (1 <= r <= n) is the identifier of the meeting room, while d, m and y are, respectively, the day (1 <= d <= 31), the month (1 <= m <= 12) and the year (1902 <= y <= 2100) for the reservation. Every triple (d,m,y) corresponds to a valid date.

Output

The output consists of a single line that contains the maximum number of requests that can be accepted.

Sample Input

2
4
1
1 28 2 2003
1
2 28 2 2003
2
1 28 2 2003
2 28 2 2003
1
1 27 2 2003

Sample Output

3


CPN'2003: 1st Concurso de Programação da Nova --- 1st Leg
Departamento de Informática
Faculdade de Ciêcias e Tecnologia
Universidade Nova de Lisboa