n, m = map(int, raw_input().split())
answer = 0

for i in xrange(m):
    arr = [int(x) for x in raw_input().split()]
    length =  arr[0]
    arr = arr[1:]
    if arr[0] == 1:
        idx = 0
        while idx < length and arr[idx] == idx + 1:
            idx += 1
        idx -= 1
        length -= idx
    answer += (2 * length) - 1


print answer - 1




