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