import sys, math
def rs():
    return sys.stdin.readline().strip()
def ri():
    return int(sys.stdin.readline().strip())
def ras():
    return list(sys.stdin.readline().strip())
def rai():
    return map(int,sys.stdin.readline().strip().split())
def raf():
    return map(float,sys.stdin.readline().strip().split())

def solve():
    n,k = rai()
    res = 0
    m = 0
    for i in xrange(k):
        t = rai()
        l = t[0]
        arr = t[1:]
        j = 0
        while j < l:
            if arr[j] != j + 1:
                break
            j += 1
        if j > 1:
            m = j
            res += l - m
        else:
            res += l - 1

    if m != 0:
        return res + n - m

    return res +  n-1



print solve()
