a,b=map(int,raw_input().split())
l=[]
ans=0
sum=0
for i in range(b):
    c=map(int,raw_input().split())
    for j in range(0,c[0]-1):
        if (c[1]==1):
                if ((c[j+1]+1)!=c[j+2]):
                    ans+=1
        elif[c[1]!=1]:
            ans+=c[0]-1
            break
    sum+=2*ans+1
    ans=0
print sum-1

