N,k = map(int,raw_input().split())
arr = []
sz =[]
for i in xrange(k):
    n = [int(i) for i in raw_input().split()]
    x=n[0]
    n.pop(0)
    sz+=[x]
    arr += [n]
ti = -1
val = N
while(val!=0):
    for i in xrange(k):
        xy = 0
        while(sz[i]!=0):
            if(arr[i][-1]!=val):
                break
            xy=1
            arr[i].pop(-1)
            val-=1
            sz[i]-=1
        if(xy!=0):
            ti+=2
            if(sz[i]==0):
                ti-=1
print ti
        
