n, k = map(int, raw_input().split())
to_open = 0
max_len = 1
for _ in range(k):
    a = map(int, raw_input().split())
    if a[1] == 1:
        for j in range(1, a[0]+1):
            if a[j] == j:
                max_len = j
            else: break
        to_open += a[0] - max_len
    else:
        to_open += a[0] - 1

print to_open + n - max_len