Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.

The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can be nested in a matryoshka with a higher number, two matryoshkas can not be directly nested in the same doll, but there may be chain nestings, for example, 1 → 2 → 4 → 5. 

In one second, you can perform one of the two following operations:
 -  Having a matryoshka *a* that isn't nested in any other matryoshka and a matryoshka *b*, such that *b* doesn't contain any other matryoshka and is not nested in any other matryoshka, you may put *a* in *b*; -  Having a matryoshka *a* directly contained in matryoshka *b*, such that *b* is not nested in any other matryoshka, you may get *a* out of *b*. 
According to the modern aesthetic norms the matryoshka dolls on display were assembled in a specific configuration, i.e. as several separate chains of nested matryoshkas, but the criminal, following the mysterious plan, took out all the dolls and assembled them into a single large chain (1 → 2 → ... → *n*). In order to continue the investigation Andrewid needs to know in what minimum time it is possible to perform this action.
The first line contains integers *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>) and *k* (1 ≤ *k* ≤ 10<sup class="upper-index">5</sup>) — the number of matryoshkas and matryoshka chains in the initial configuration.

The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m*<sub class="lower-index">*i*</sub> (1 ≤ *m*<sub class="lower-index">*i*</sub> ≤ *n*), and then *m*<sub class="lower-index">*i*</sub> numbers *a*<sub class="lower-index">*i*1</sub>, *a*<sub class="lower-index">*i*2</sub>, ..., *a*<sub class="lower-index">*im*<sub class="lower-index">*i*</sub></sub> — the numbers of matryoshkas in the chain (matryoshka *a*<sub class="lower-index">*i*1</sub> is nested into matryoshka *a*<sub class="lower-index">*i*2</sub>, that is nested into matryoshka *a*<sub class="lower-index">*i*3</sub>, and so on till the matryoshka *a*<sub class="lower-index">*im*<sub class="lower-index">*i*</sub></sub> that isn't nested into any other matryoshka).

It is guaranteed that *m*<sub class="lower-index">1</sub> + *m*<sub class="lower-index">2</sub> + ... + *m*<sub class="lower-index">*k*</sub> = *n*, the numbers of matryoshkas in all the chains are distinct, in each chain the numbers of matryoshkas follow in the ascending order.
##row, col, order = input().split(' ')    
##row = int(row)
##col = int(col)
##
##init_list = []
##
##for i in range(row):
##    init_list.append(input().split(' '))
##
##if order=='0':
##    for i in range(row):
##        print()
##        for j in range(col,0,-1):
##            print(init_list[i][j-1], end = ' ')
##else:
##    for i in range(row,0,-1):
##        print()
##        for j in range(col):
##            print(init_list[i-1][j], end = ' ')

def judge(_list:list) -> bool:
    for i in range(len(_list)):
        if int(_list[i]) == i+1:
            pass
        else:
            return False

    return True

mat_num, chain_num = input().split(' ')
mat_num, chain_num = int(mat_num), int(chain_num)

chain = []

for i in range(chain_num):
    chain.append([])
    temp_list = input().split(' ')
    for j in range(int(temp_list[0])):
        chain[-1].append(temp_list[1])
        del temp_list[1]

for i in range(chain_num):
    if judge(chain[i]):
        chain[i] = [1]
    else:
        pass

time = 0
count = 0

for i in range(chain_num):
    time += len(chain[i]) - 1
    count += len(chain[i])

print(time + count -1)
