[n,k] = [int(i) for i in input().split()]
#print(n, k)
unnest = 0
chains = k
for mats in range(0, k):
    arr = [int(i) for i in input().split()]
    m = arr[0]
    if m == 1:
        continue
    for i in range (2, m+1):
        #print("Here")
        if arr[i]!=arr[i-1]+1:
            unnest += m-i+1
            chains+= m-i+1
            break
#print(unnest, chains)
print(unnest + chains - 1)