n, k = map(int, input().split())
time = 0
part = 0
for i in range(k):
    m = list(map(int, input().split()))
    p = m[0]
    d = set(m[1:])
    cou = 0
    if 1 in d:
        for i in range(1, p):
            if m[i] == m[i + 1] - 1:
                cou += 1
            else:
                break
        part += p - cou
        time += p - cou - 1
    else:
        part += p
        time += p - 1
time += part - 1
print(time)