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 = 1
    if 1 in d:
        i = 1
        while i < p and m[i] == m[i + 1] - 1:
            i += 1
            cou += 1
        if cou != 1:
            part += p - i + 1
            time += part - 1
        else:
            part += p
            time += p - 1
    else:
        part += p
        time += p - 1
time += part - 1
print(time)