Defragment

No attempts yetTime limit1sMemory limit128 MB

Problem

You are developing the file system for a new operating system. All disk space is divided into NN equally sized clusters, numbered from 11 to NN. Each file occupies one or more clusters located at arbitrary positions on the disk. Every cluster not occupied by a file is considered free.

A file can be read fastest when all of its clusters lie in consecutive clusters in their natural order. Because the disk rotates at a constant speed, clusters near the beginning are read faster than clusters near the end, so the files are numbered from 11 to KK in order of decreasing access frequency. In the optimal layout, file 11 occupies clusters 1,2,,S11, 2, \dots, S_1, file 22 occupies clusters S1+1,,S1+S2S_1+1, \dots, S_1+S_2, and so on, where SiS_i is the number of clusters that file ii occupies.

To reach the optimal layout you perform cluster-moving operations. One cluster-moving operation reads the contents of one occupied cluster and writes them to a free cluster; afterwards the source cluster becomes free and the destination cluster becomes occupied.

Compute the minimum number of cluster-moving operations required to place all files in the optimal layout.

Input

The first line contains two integers NN and KK separated by a space (1K<N100001 \le K < N \le 10000). Each of the next KK lines describes one file. The description of the ii-th file starts with the integer SiS_i, the number of clusters in file ii (1Si<N1 \le S_i < N), followed by SiS_i integers giving the cluster numbers occupied by that file in natural order.

All cluster numbers in the input are distinct, and there is always at least one free cluster.

Output

Print a single integer: the minimum number of cluster-moving operations needed to place all files in the optimal layout. If the files are already in the optimal layout, print 00.