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:
    cur = i[0]
    j = 1
    b.append([])
    while (j < len(i)) and (i[j] == cur + 1):
        cur = i[j]
        j += 1
    b[-1] = [j] + [1] * (len(i) - j)
    curt += len(b[-1])
fin = curt - 1
#print(b)
for i in b:
    fin += len(i) - 1
print(fin)
