
n,m=(int(x) for x in input().split())
count=0
for i in range(m):
    a=[int(x) for x in input().split()]
    for j in range(1,a[0]-1):
        if a[j]!=a[j+1]-1:
            count+=1
print(2*count+m-1)
