n, m = [int(x) for x in input().split()]
a = []
for i in range(m):
    a.append([int(x) for x in input().split()][1:])
b = []
curt = 0
for i in a:
    j = 0
    b.append([])
    while (j < len(i)) and (i[j] == (j + 1)):
        j += 1
    if j != 0:
        b[-1] = [j]
    b[-1] += [1] * (len(i) - j)
    curt += len(b[-1])
fin = curt - 1
#print(b)
for i in b:
    fin += len(i) - 1
print(fin)
