n,k = map(int,raw_input().split())

def seq_len(p):
    l = 1
    for i in xrange(1,len(p)-1):
        if p[i+1] - p[i] != 1:
            break
        l +=1
    return l

left = 0
steps = 0
for _ in xrange(k):
    p = [int(x) for x in raw_input().split()]
    s = seq_len(p)
    left += (p[0]+1-s)
    steps += (p[0] - s)

steps += (left-1)

print steps
