n,k = map(int,input().split(" "))
i=0
res=k
while i<k:
    i+=1
    mas=list(map(int,input().split(" ")))[1:]
    mas.reverse()
    j=0
    while j<(len(mas)-1):
        if(mas[j]-1!=mas[j+1]):break
        else:j+=1
    res+=2*(len(mas)-j-1)
print(res-1)
